How to avoid invalid path error message on saving a new file with scripting command UltraEdit.saveAs?

How to avoid invalid path error message on saving a new file with scripting command UltraEdit.saveAs?

4
NewbieNewbie
4

    May 20, 2019#1

    I am calling UE from Excel using Visual Basic. The UE script does a bunch of file manipulations and at the end has an UltraEdit.saveAs command that works successfully.
    But when I go to close the file that I saved I get the following error: IPEX_SearchReplace.js contains an invalid path.
     
    Here is the code that creates the file name and path to execute the saveAs and close the file:

    Code: Select all

        var now = new Date();
        var month = now.getMonth();
        month = month + 1;
        if (month < 10) {
           month = "0" + month;
        }
        var day = now.getDate();
        if (day < 10) {
           day = "0" + day;
        }
        var hours = now.getHours();
        if (hours < 10) {
           hours = "0" + hours;
        }
        var minutes = now.getMinutes();
        if (minutes < 10) {
           minutes = "0" + minutes;
        }
        var seconds = now.getSeconds();
        if (seconds < 10) {
           seconds = "0" + seconds;
        }
        
        var sPath="H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\"
              + sTransSet 
              +"_"
              + sDocNum
              + "_"
              + now.getFullYear()
              + month
              + day
              + "-"
              + hours
              + minutes
              + seconds
              + ".txt";
        UltraEdit.saveAs(sPath);
     // Free memory and switch back to Windows clipboard.
        UltraEdit.clearClipboard();
        UltraEdit.selectClipboard(0);
    
    // This is the line that errors out when executing from excel, but does not error out when script is run directly from UE
        UltraEdit.closeFile(sPath,2);
    But if I run the script from UltraEdit I don't get the error. Why does it work one way, but not the other?
    What am I doing wrong?

    Thank you.

    6,603547
    Grand MasterGrand Master
    6,603547

      May 20, 2019#2

      The error message is most likely no caused by:

      Code: Select all

      UltraEdit.closeFile(sPath,2);
      This line can be perhaps replaced by:

      Code: Select all

      UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
      But it looks like the error message is caused by an error on Visual Basic line which runs UltraEdit with the file to modify and the script to execute. Please post the relevant part of the Visual Basic macro used to run UltraEdit.
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        May 21, 2019#3

        Good morning Mofi,

        The Visual Basic code is as follows: 

        Code: Select all

        Sub A1_Execute_UltraEdit()
            FileList = 2
            Do While Trim(Sheet1.Cells(FileList, 1).Value) <> ""
                IPEX_Original = Sheet1.Cells(FileList, 1).Value
        
                sScript = "/s=" & """H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js """
        
                Shell_Command = """C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe""" & sScript & """ & IPEX_Original & """
        
                Shell Shell_Command, vbNormalFocus
                FileList = FileList + 1
            Loop
        End Sub
        The code you suggested worked to close the file, but now I need to exit and close UE. Which I have not been able to do.
        Also need to modify the vb to wait for UE to return the control. Which I am not sure how to do either.

        Thank you for all your help.

        6,603547
        Grand MasterGrand Master
        6,603547

          May 21, 2019#4

          I suggest to change the line

          Code: Select all

          sScript = "/s=" & """H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js """
          to

          Code: Select all

          sScript = " /fni /s,e=""H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js"" "
          /fni as first (important) parameter forces a new instance of UltraEdit which is very important on using default configuration setting with not checked Allow multiple instances.It is important that the strings sScript starts with a space character to concatenate this arguments list string correct with a space as argument separator with full qualified UltraEdit executable file name enclosed in double quotes.

          ,e after /s results in exiting UltraEdit instance after script execution finished.

          And last the script file name does not end with a space character. So it is necessary to you have the "" immediately after script file name and then one more space in string as argument separator before next argument string.

          So the final command line to execute is:

          Code: Select all

          "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" /fni /s,e="H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js" "IPEX_Original string"
          Best regards from an UC/UE/UES for Windows user from Austria

          4
          NewbieNewbie
          4

            May 21, 2019#5

            Hi Mofi,
             
            I must have done something to cause this or I have a setting not set in UE as now I get the error that it can't create the temporary file.
            See attached image for print screen of the error.

            And it errors out on line 16 of the script:

            Code: Select all

            An error occurred on line 16:
                UltraEdit.activeDocument.bottom();
            Script failed.
            Here is the UE shell call command I am executing now, without the ,e so I could see the errors:

            Code: Select all

            "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe " /fni /s="H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js" "H:\IPEX\DataFiles\IPEX_Originals\856_1002_X12.txt"
            Thank you.
            error_message_cant_create_temporary_file.png (1.68KiB)
            Error message: "Can't create temporary file"

            6,603547
            Grand MasterGrand Master
            6,603547

              May 21, 2019#6

              Look on the command line executed by Visual Basic code. There is a space character between uedit64.exe and ". This space is wrong. There should be no space between file extension and double quote.

              I created in a *.xlsm file the Visual Basic macro:

              Code: Select all

              Sub A1_Execute_UltraEdit()
              
                  Dim IPEX_Original As String
                  Dim sScript As String
                  Dim Shell_Command As String
              
                  IPEX_Original = "H:\IPEX\DataFiles\IPEX_Originals\856_1002_X12.txt"
                  sScript = " /fni /s,e=""H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js"" "
              
                  Shell_Command = """C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe""" & sScript & """" & IPEX_Original & """"
              
                  Shell Shell_Command, vbNormalFocus
              
              End Sub
              Everything worked as expected on execution of this subroutine with clicking on green arrow button with file H:\IPEX\DataFiles\IPEX_Originals\856_1002_X12.txt existing.

              Please note that there are twice four " on line which concatenates the strings to Shell_Command with final string:

              Code: Select all

              "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" /fni /s,e="H:\IPEX\Ultraedit scripts\IPEX_SearchReplace.js" "H:\IPEX\DataFiles\IPEX_Originals\856_1002_X12.txt"
              """" defines a string with an escaped double quote character as only character of the string.
              Best regards from an UC/UE/UES for Windows user from Austria

              4
              NewbieNewbie
              4

                May 21, 2019#7

                I fixed all of that but it continues to tell me it can't create temporary file H:\IPEX\DataFiles\IPEX_Originals\856_1002_X12.txt

                I have done a cleanup of all temporary files and still the error persists.

                6,603547
                Grand MasterGrand Master
                6,603547

                  May 22, 2019#8

                  I don't know what causes this error message on your computer which does not occur on my computer. I also don't know when this error message is displayed at all.

                  Does the file H:\IPEX\DataFiles\IPEX_Originals\856_1002_X12.txt exist already on starting UltraEdit by the Visual Basic macro in Excel as it is the case on my computer?

                  When have you last time executed Disk Cleanup tool of Windows as normal user or as administrator to delete all files and directories offered by this Microsoft Windows tool for cleanup including the files and subdirectories in %TEMP%. The files and subdirectories in %SystemRoot%\Temp must be deleted manually as administrator. This directory is not used by UltraEdit, just by processes running under system account.

                  On using already UltraEdit v25.20 or a later version the temporary files are created in directory %APPDATA%\IDMComp\UltraEdit\Restore. Make sure that UltraEdit has write access to this directory in environment on execution by Visual Basic macro in Excel file.

                  Do you run the Visual Basic macro in Excel file as part of a scheduled task running under system account?

                  Is drive H: a local drive or a network drive?
                  Best regards from an UC/UE/UES for Windows user from Austria