Convert regular expression to lowercase on all open files

Help with writing and playing macros

Convert regular expression to lowercase on all open files

Postby GoalSetter40s » Fri Jan 12, 2007 8:52 pm

I just upgraded to UltraEdit 12.20b.

I have a macro created that does exactly what I want it to do on the currently opened file, but I want to run this macro on a file containing list of files, or using a files specified with wildcard characters.

The issue I'm having is that when using the syntax specified in the help documentation (/M,E,5="full path of macro file/macro name"), my macro only runs completely on the file that with the tab in focus. The other non-focused tabs, only seem to run a section of the macro, such as lines 16-18.

Below is my macro (I've numbered each line for ease of reading). As you can see, I'm doing some simple search and replace using regular expressions, but the challenge is the sections in the macro where I'm converting certain strings to all lowercase, such as the (4) four separate loops contained in lines 19-62. Lines 19-62 don't run on all the opened files, just the one that has focus.

I guess my real question is how write a macro that will run against a file containing list of files, or using files specified with wildcard characters that will converts certain strings to lowercase


1 InsertMode
2 ColumnModeOff
3 HexOff
4 UnixReOff
5 Top
6 Loop
7 Find RegExp "http://old.domain.com/pictures-uploads*[\]"
8 IfNotFound
9 ExitLoop
10 EndIf
11 Key LEFT ARROW
12 Delete
13 "/"
14 Top
15 EndLoop

16 Top
17 Find "http://old.domain.com/pictures-uploads/"
18 Replace All ALLFiles "http://new.domain.com/"

19 Top
20 Loop
21 Find RegExp "http://new.domain*.gif"
22 IfNotFound
23 ExitLoop
24 EndIf
25 ToLower
26 EndSelect
27 Key LEFT ARROW
28 Key RIGHT ARROW
29 EndLoop

30 Top
31 Loop
32 Find RegExp "http://new.domain*.jpg"
33 IfNotFound
34 ExitLoop
35 EndIf
36 ToLower
37 EndSelect
38 Key LEFT ARROW
39 Key RIGHT ARROW
40 EndLoop

41 Top
42 Loop
43 Find RegExp "http://new.domain*.jpeg"
44 IfNotFound
45 ExitLoop
46 EndIf
47 ToLower
48 EndSelect
49 Key LEFT ARROW
50 Key RIGHT ARROW
51 EndLoop

52 Top
53 Loop
54 Find RegExp "http://new.domain*.png"
55 IfNotFound
56 ExitLoop
57 EndIf
58 ToLower
59 EndSelect
60 Key LEFT ARROW
61 Key RIGHT ARROW
62 EndLoop
User avatar
GoalSetter40s
Newbie
 
Posts: 2
Joined: Fri Jan 12, 2007 12:00 am

Re: Convert regular expression to lowercase on all open file

Postby Mofi » Sat Jan 13, 2007 12:54 pm

You need 2 macros in the macro file for this job because nested loops are not possible. The first macro you have to create is the one you already have. Here is again your slightly improved macro. You can see that the macro is now designed to run on the current file only.

Top
Loop
Find RegExp "^(http://pictures.mlsvo.com/pictures-uploads*^)\"
Replace All "^1/"
IfNotFound
ExitLoop
EndIf
EndLoop
Find "http://pictures.mlsvo.com/pictures-uploads/"
Replace All "http://upl.srspictures.com/"
Loop
Find RegExp "http://upl.srspictures*.gif"
IfNotFound
ExitLoop
EndIf
ToLower
EndSelect
Key LEFT ARROW
Key RIGHT ARROW
EndLoop
Top
Loop
Find RegExp "http://upl.srspictures*.jpg"
IfNotFound
ExitLoop
EndIf
ToLower
EndSelect
Key LEFT ARROW
Key RIGHT ARROW
EndLoop
Top
Loop
Find RegExp "http://upl.srspictures*.jpeg"
IfNotFound
ExitLoop
EndIf
ToLower
EndSelect
Key LEFT ARROW
Key RIGHT ARROW
EndLoop
Top
Loop
Find RegExp "http://upl.srspictures*.png"
IfNotFound
ExitLoop
EndIf
ToLower
EndSelect
Key LEFT ARROW
Key RIGHT ARROW
EndLoop


The second macro you need is the macro you must specify on the command line (1 execution only) or which you must run if you have all files open in UltraEdit. It calls your macro above until no file is opened anymore and so all previously opened files are saved and closed with the modifications.

This is a simple macro to run another macro on all open NAMED files. It is not working if new files not already saved at least once (= don't have a file name) are open.

The macro property Continue if a Find with Replace not found must be checked for this main macro because the macro properties of this macro are also used for the submacro called. The macro properties of the submacro are ignored when executed with PlayMacro command.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Loop
IfNameIs ""
ExitLoop
EndIf
PlayMacro 1 "case-sensitive name of your macro"
Save
CloseFile
EndLoop

For a second method to run a macro on all open files (including new files) without closing the files is posted at How do you run a Macro on open files?
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Convert regular expression to lowercase on all open file

Postby GoalSetter40s » Mon Jan 15, 2007 9:12 pm

Mofi, thank you so much! The macro you re-wrote for me and the new macro you created worked perfectly!!!

This forum offers the best tech support of any company I have ever experienced. Keep up the good work!
User avatar
GoalSetter40s
Newbie
 
Posts: 2
Joined: Fri Jan 12, 2007 12:00 am


Return to Macros