Open a file from a path specified in another file

Open a file from a path specified in another file

2
NewbieNewbie
2

    May 23, 2011#1

    Hi there,

    I would like to create a macro to open a file found in various locations, in a new tab. I created a *.ini file which stores the path of the file. So, my macro should open the ini file which is stored at a fixed location, easy command, open "C:\Temp\test.ini", then go to a line that has another file location/path. Normally, you are able to select the path, right click on it, then first option open. This is not catched in the Macro Recorder.
    I tried to use the %sel% key word, it won't work.
    Alternatively, I tried to create another Tool which is able to open a new instance of UltraEdit with the file by using uedit32.exe %sel%. This works standalone, but when asembled in a macro it crashes, that probably because the macro open command knows only absolute paths.
    Third option would be to have some Key command to simulate a Right Click then Down Arrow, Enter.

    Is there any way I can do this?
    My version of UE is 12.20b+1

    Thanks in advance!

    Regards,
    Daniel

    6,602548
    Grand MasterGrand Master
    6,602548

      May 23, 2011#2

      First, UltraEdit can be started with the parameter /f"file list file". So if you create a shortcut to uedit32.exe and append on the command line of the shortcut /fC:\Temp\test.ini you perhaps don't need a macro to start UltraEdit with a dynamically created list of files to open. The "file list file" must contain only file names with full path, one file per line. Double quotes around the file name of the list file are only needed if the full file name of the list file contains 1 or more spaces. That is the method I use to start UltraEdit with a file list file created by my favorite file manager Total Commander which creates that list file in temp folder and deletes it also automatically on exit of UltraEdit.

      To open files with a macro from a list of files use following macro:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      Open "C:\Temp\test.ini"
      Bottom
      IfColNumGt 1
      InsertLine
      IfColNumGt 1
      DeleteToStartofLine
      EndIf
      EndIf
      Top
      Loop
      IfEof
      ExitLoop
      EndIf
      StartSelect
      Key END
      IfSel
      Open "^s"
      IfSel
      Else
      PreviousWindow
      EndIf
      EndIf
      EndSelect
      Key HOME
      Key DOWN ARROW
      EndLoop
      CloseFile NoSave
      The macro opens the list file. Next it first checks if the last line of the file has a line termination. If there is no line termination at end of file, it inserts one and makes sure that no additional spaces/tabs are inserted in case last line of file starts with spaces/tabs and auto-indent feature is enabled although this is most likely not the case for this file. It is extremly important for this macro that there is a line termination at end of file otherwise the following loop would be really an endless loop.

      Inside the loop first a check is done if the caret in the list file has reached end of file and if this is true, the loop is exited and the list file is closed without saving it in case it was modified.

      The main loop task is to select active line without line termination and use the selected string in the File Open command referenced by ^s. In case the current line is a blank line, it is ignored. If the file could not be opened, the list file is still active. Therefore the switch back to the list file with command PreviousWindow is done only when nothing is selected in active file which is true for just opened files.

      A regular expression find could be also used to select names of files. But then the condition to break the loop must be IfNotFound below the Find command instead of IfEof. The caret is not moved to end of file if a searched string is not found anymore in file and therefore IfEof would not become true ever.


      For opening a file in a new instance of UltraEdit whose file name is currently selected in the active file, you can use a user tool with following command line:

      "full path to uedit32.exe\uedit32.exe" /fni "%sel%"

      The double quote characters arround %sel% are important in case of 1 or more spaces in selected file name. Please note that the program type for this tool must be Windows program because UltraEdit is not a DOS or console application.

      Correction: The parameter /fni (force new instance) was introduced with UE v13.10 and is therefore not available in your old version of UltraEdit. So you have to enabled configuration setting Allow multiple instances to be able to open a file whose name is selected in active file in a new instance of UltraEdit.

      2
      NewbieNewbie
      2

        May 24, 2011#3

        Hi Mofi,

        Thank you very much for your reply. Plenty of good info in there.
        Open "^s" did the job for me, although only within the Ifsel condition, which is actually better coding.
        Pushing my luck a little bit, is there a way to create a custom button for a macro? I know a keyboard shortcut is usually better but a button is best sometimes.

        Thanks once again for your answer!

        Regards,
        Daniel

        6,602548
        Grand MasterGrand Master
        6,602548

          May 24, 2011#4

          dafau wrote:Pushing my luck a little bit, is there a way to create a custom button for a macro?
          No! Macros stored in a macro file which is automatically loaded on startup of UltraEdit can be executed only by hotkey, by using Macro - Play Any/Multiple Times or by double clicking on the macro name in the Macro List view. It is not possible to customize the toolbar or menu and add a macro execution command for a macro stored in the automatically loaded macro file to a toolbar or menu because no such command exists.