Convert regular expression to lowercase on all open files

Convert regular expression to lowercase on all open files

5

    Jan 13, 2007#1

    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

    6,675585
    Grand MasterGrand Master
    6,675585

      Re: Convert regular expression to lowercase on all open file

      Jan 13, 2007#2

      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?
      Best regards from an UC/UE/UES for Windows user from Austria

      5

        Re: Convert regular expression to lowercase on all open file

        Jan 16, 2007#3

        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!