IfNameIs not working in macro executed on each file load for FTP/SFTP loaded file

IfNameIs not working in macro executed on each file load for FTP/SFTP loaded file

49
Basic UserBasic User
49

    Jul 27, 2017#1

    Hi,

    Every day I need to open some log files that have session id appended to the name of the file which is not really an extension. I started writing a macro which I could "Set macro for File Load/Save" to accomplish a task. Didn't get too far with it so I am asking for help.

    I have a file named /rsmprod/sasautos/logs/1027/aml_excprpt_01_ods_extr.sas.saslog.21420. I added the following commands to the macro:

    Code: Select all

    IfNameIs "aml_excprpt_01_ods_extr.sas.saslog"
    Find "o'clock"
    Replace "o clock"
    EndIf
    But this doesn't seem to work. When I open the file, it does not perform the Replace operation. Without the IfNameIs condition, it works.

    I am using UEP 16.00. Any help is appreciated.

    6,686586
    Grand MasterGrand Master
    6,686586

      Jul 28, 2017#2

      The macro works for me for this file loaded from local hard disk.
      Best regards from an UC/UE/UES for Windows user from Austria

      49
      Basic UserBasic User
      49

        Jul 28, 2017#3

        Mofi, thanks for the reply.

        Hmm... The macro works for you, but strangely not for me. Can you please let me know exactly what you did to recreate the scenario. May be I am missing something here.

        6,686586
        Grand MasterGrand Master
        6,686586

          Jul 29, 2017#4

          The steps I made with UltraEdit for Windows v24.10.0.32 for file name specific macro execution on file load:
          • I started UltraEdit resulting in getting displayed a new ANSI file with code page Windows-1252.
          • I copied in browser o'clock to clipboard with Ctrl+C and pasted this text into the new file with Ctrl+V.
          • I copied in browser the file name aml_excprpt_01_ods_extr.sas.saslog.21420 with Ctrl+C, hit back in UltraEdit key F12 to open Save as window, pasted into File name edit field the file name with Ctrl+V, made sure that Save as type displayed All files, (*.*) and Encoding displayed Default and hit key RETURN to save the file.
          • I closed the file with Ctrl+F4.
          • With using Toolbar/menu mode with Traditional menus (my preferred GUI mode) I clicked in menu Macro on Delete all to unload all macros which are loaded on startup from a macro file as I did not want to mix them with the test macro.
          • I clicked in menu Macro on Edit macro and next in opened dialog window on New macro.
          • I entered as Macro name OnFileLoad, hit key TAB and next SPACE to uncheck macro property Show cancel dialog for this macro, but let macro property Continue if search string not found checked, and hit key RETURN to close the Macro Definition window with default button OK.
          • I switched once again to browser with Alt+TAB and copied the macro code after selecting it with Ctrl+C to clipboard.
          • I switched back to UltraEdit with Alt+TAB, pressed Alt+M and hit key TAB to set input to macro code edit area with the 3 existing lines already selected and pressed Ctrl+V to replace them with copied code in clipboard.
          • I pressed Alt+L to execute Close and hit key RETURN to confirm with Yes to update the macro.
          • I clicked in menu Macro on Save all, entered as file name OnLoadSave and hit key RETURN to Save the macro into this macro file. The macro file was saved into directory F:\Temp which is my default directory for temporary files (not the one environment variable TEMP references).
          • I clicked in menu Macro on Set macro for file load/save, clicked on button Browse and double clicked on  file OnLoadSave.mac to select this macro file.
          • I entered in edit field of Macro name to run on load the macro name OnFileLoad, pressed TAB, replaced selected value 0 by 1 for # of times and hit key RETURN to activate OK.
          • I opened in menu File the submenu Recently opened files and clicked on first item F:\Temp\aml_excprpt_01_ods_extr.sas.saslog.21420.
          And the result was: file loaded without any modification. What? I could not believe that as it worked 2 days ago.

          I exited UltraEdit and replaced UE v24.10.0.32 by v24.10.0.24 from my archives, started this version and opened the file, no replace. I made the same steps also with v24.00.0.76 and v24.00.0.42 always using same configuration files from v24.10.0.32, but no replace on file open. So I replaced v24.00.0.42 by v23.20.0.43, started it and did all the steps described above once again as UE v23.20 is not compatible with Unicode configuration files and Unicode macros of UE v24.00+. And the replace was done on opening the file.

          So I thought that there is probably an issue caused by making UltraEdit a full Unicode aware application. I restored v24.00.0.42 and checked everything once again and detected that # of times had the value 0 instead of 1. I'm quite sure that I have entered 1 before. However, I fixed this configuration issue and the macro executed the replace on file load as expected. I restored v24.10.0.32 without changing configuration and macro worked too.

          I exited UltraEdit v24.10.0.32, deleted the application data directory of UltraEdit completely and made the same steps as written above once again on new configuration created automatically by UltraEdit. And the macro worked on opening the file as it should.

          So I restored my preferred configuration from a backup I always have for such test cases and for security and stopped looking on this issue.

          I have most likely really not set value 1 for # of times as I executed the steps above the first time and wrote at the same time the steps in browser window.
          Best regards from an UC/UE/UES for Windows user from Austria

          49
          Basic UserBasic User
          49

            Jul 31, 2017#5

            Thanks Mofi for a very detailed reply.

            I didn't see anything different you did than what I had. So, the only thing that could be causing the issue is the filename itself. When I create the file in Windows the same way you did, it works fine. However, I am opening a file from Unix. When I open the file from Unix, it doesn't work. The filename in Unix has "/" as the path separator as opposed to "\" in Windows. It is not possible to create a file with "/" in the filename in Windows as I tried and it didn't let me.

            It looks like the macro command "IfNameIs" does not recognize "/" as the path separator. If that is the case, it may not work at all for Unix files.

            Your thought on this please?

            6,686586
            Grand MasterGrand Master
            6,686586

              Re: Conditional highlighting if filename contains a string

              Aug 01, 2017#6

              You do perhaps something wrong if you open a file on Windows with / in file path instead of \. The Windows file system kernel functions correct since Windows NT4 invalid paths using / as directory separator instead of \ by first replacing all / by \ which can be watched using Process Monitor of Sysinternals. On Windows 9x using / in a file path resulted in failure on accessing the file if I remember correct.

              However, it looks like UltraEdit applies the IfNameIs on the file name string passed to UltraEdit and does not automatically replace all / by \ before like the Windows file system kernel functions do inside. UltraEdit can't do that as it is possible to open files via FTP/FTPS/SFTP in which case there are / in file path which must be kept.

              I cannot really answer your question as long as you don't post how you open the file using / as directory separator instead of a backslash.
              Best regards from an UC/UE/UES for Windows user from Austria

              49
              Basic UserBasic User
              49

                Aug 01, 2017#7

                I open the file via FTP account which connects to my Unix id with IP address, id and password. In Unix world, all paths are separated by "/" as against "\". Just for the heck of it, I even tried using the complete file name excluding the last portion in the macro, but it still doesn't work. Here is the revised version of the macro:

                Code: Select all

                InsertMode
                ColumnModeOff
                HexOff
                IfNameIs "/rsmprod/sasautos/logs/1027/aml_excprpt_01_ods_extr.sas.saslog"
                Find "o'clock"
                Replace "o clock"
                EndIf
                Not that even if this worked, it was any good to me but I wanted to see if the macro considers "/" as part of the filename and IfNameIs might return everything except the last bit after the period.

                6,686586
                Grand MasterGrand Master
                6,686586

                  Aug 02, 2017#8

                  I'm using usually not FTP feature of UltraEdit and therefore needed a while to setup an environment where I can look on this issue.

                  A macro containing IfExtIs, IfFTP or IfNameIs executed manually works fine in UE v24.10.0.35 also for files loaded via FTP.

                  The macro command must be for your file: IfNameIs "aml_excprpt_01_ods_extr.sas.saslog"

                  So executing the macro manually after loading the file via FTP works. The file name with extension and path is in UltraEdit:

                  FTP::AccountName\//rsmprod/sasautos/logs/1027|aml_excprpt_01_ods_extr.sas.saslog.21420

                  That is displayed with using default settings of UltraEdit 24.10.0.35 in title bar of UltraEdit's main application window.

                  So there is no problem with correct detecting that the file name is aml_excprpt_01_ods_extr.sas.saslog.

                  But when the same macro is used for automatic execution on each file load, the macro commands IfExtIs, IfFTP and IfNameIs do not work for files loaded via FTP/FTPS/SFTP as expected. There are only working for files loaded from a local storage media, network drive or network share using UNC path.

                  It looks like the data accessed by the 3 commands IfExtIs, IfFTP and IfNameIs are not set for FTP/FTPS/SFTP loaded files correct at the time when the macro is executed on file load.

                  I wrote following macro for execution on each file load for a file with test.txt as name to verify this assumption:

                  Code: Select all

                  InsertMode
                  ColumnModeOff
                  HexOff
                  IfNameIs "test"
                  "Name is test"
                  Else
                  IfNameIs ""
                  "Name is empty"
                  Else
                  "Name is unknown"
                  EndIf
                  EndIf
                  IfExtIs "txt"
                  " - extension is txt"
                  Else
                  IfExtIs ""
                  " - extension is empty"
                  Else
                  " - extension is unknown"
                  EndIf
                  EndIf
                  IfFTP
                  " - no FPT file"
                  Else
                  " - is FTP file"
                  EndIf
                  CopyFilePath
                  "
                  "
                  Paste
                  "
                  
                  "
                  And it was really interesting for me to see what this macro writes into the file test.txt on loading it via FTP and when executed it after loading once again manually. The macro completely confirms what I thought.

                  I reported this issue to IDM support by email as it should not make a difference on macro execution on file load if the file is loaded via FTP/FTPS/SFTP or from a local storage media, network drive or network share.

                  And while playing around to investigate this issue I detected another issue with macro execution on file load with UE v24.10.0.35. The macro to execute on load 1 times is executed twice when a file not loaded via FTP/FTPS/SFTP is opened from recently opened or recently closed list. Opening the file with other methods like using File - Open or drag & drop from another application into UltraEdit main window or using Quick Open or double clicking on Explorer tab of File View or drag & drop the file from Explorer tab of File View into document window area work as expected with only one execution of the macro. The other methods to open a file were not tested by me up to now. I reported this second issue also by email to IDM support.
                  Best regards from an UC/UE/UES for Windows user from Austria

                  49
                  Basic UserBasic User
                  49

                    Aug 03, 2017#9

                    Thanks a lot Mofi. You are so thorough with everything. I really admire that.

                    Now that we know it is an issue with UE, I can stop trying to make it work and wait for IDM's fix, if and when it comes.

                    While on it, can I ask one more thing. Is there a way in a macro to check existence of a string in the filename downloaded via FTP. I just need to check existence of the string "saslog" in the filename, whether in the full filename or just from result of IfNameIs.

                    6,686586
                    Grand MasterGrand Master
                    6,686586

                      Aug 03, 2017#10

                      UltraEdit macros don't support variables and it is not possible to search directly in the name of a file with full path as it is possible in script environment because of JavaScript String class having methods to run a find/replace on string value.

                      So for searching for a string in name of a file it is necessary to copy the file name, paste it into a file and search in file for the string.

                      Example 1 modifying the active file to search for saslog in file name.

                      Code: Select all

                      InsertMode
                      ColumnModeOff
                      Top
                      Clipboard 9
                      CopyFilePath
                      Paste
                      ClearClipboard
                      Clipboard 0
                      "
                      "
                      Find Up "saslog"
                      IfFound
                      DeleteLine
                      Else
                      Top
                      DeleteLine
                      EndIf
                      Additional commands to execute in true branch of IfFound must be inserted below first occurrence of command DeleteLine.

                      Example 2 opening a new file to search for saslog in file name.

                      Code: Select all

                      Clipboard 9
                      CopyFilePath
                      NewFile
                      Paste
                      ClearClipboard
                      Clipboard 0
                      "
                      "
                      Find Up "saslog"
                      IfFound
                      CloseFile NoSave
                      Else
                      CloseFile NoSave
                      EndIf
                      Additional commands to execute in true branch of IfFound must be inserted below first occurrence of command CloseFile NoSave. This solution depends on what is configured for After current tab is closed, move to: at Advanced - Settings or Configuration - Application Layout - File Tabs - Miscellaneous. And it could not work as expected for a macro being executed on file load. I did not test it for this use case.

                      But I suggest to search for something SAS log file specific in contents of opened file to identify the file as SAS log file. For faster detection the find could be restricted to a selected block at top for not searching in an entire large file which is not a SAS log file for the string. Something like:

                      Code: Select all

                      InsertMode
                      ColumnModeOff
                      Top
                      GotoLineSelect 20
                      IfSel
                      Find SelectText "Whatever is a strong indication for an SAS log file."
                      IfFound
                      Top
                      EndIf
                      EndIf
                      Top
                      Additional commands to execute within IfFound block must be inserted below second occurrence of command Top within this code block.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      49
                      Basic UserBasic User
                      49

                        Aug 04, 2017#11

                        Thanks a lot Mofi.

                        Although all of your examples are great but I like the last one the most. That one one does not require a new file to be opened and closed which I think is cleaner. I will go with that one. I can use our SAS license number to search which will exist only in a SAS log file.

                        Thanks again for your help and support.
                        Subhash.