Tapatalk

uedit64 command line with macro from inside PowerShell

uedit64 command line with macro from inside PowerShell

2
NewbieNewbie
2

    Mar 03, 2017#1

    Can anyone help?

    I'm running uedit64 from PowerShell. It won't exit the editor. I have to close/exit the editor window manually.

    UltraEdit Text/Hex Editor (x64)
    Version 24.00.0.53

    PowerShell:

    Code: Select all

    $In = "\\pubtech\users\pubtechops2\My Documents\UltraEdit Files\TEST FILES MOVE N9"
    
    Get-ChildItem -Path $In -recurse -Include *.edi | ? { $_.FullName -inotmatch 'archive' } |
    Foreach-Object {
        $_.FullName
        & uedit64 /fni $_.FullName /M,E "C:\SCRIPTS\Move N9.mac" | out-null
    }
    
    Note: If I add the = to the /M,E on the command line it won't find the macro. I get a "macro load" popup. Saying it can't find the macro.
    The path in the popup is correct. If I take out the = the macro runs but it wont exit or close properly.

    MACRO: (I'm doing more, but just this simple bit wont close the editor window, which stops my PowerShell from looping to the next file.)

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UltraEditReOn
    Key Ctrl+HOME
    Find "ST*180"
    IfNotFound
    CloseFile NoSave
    ExitMacro
    Else
    CloseFile NoSave
    ExitMacro
    EndIf
    

    6,685587
    Grand MasterGrand Master
    6,685587

      Mar 08, 2017#2

      I don't know anything about syntax of PowerShell and therefore can't really help. I'm quite sure you can find a solution for your PowerShell coding issue on Stack Overflow.

      However, it looks like you want to search for files in a directory and for each found file you want to
      • Start UltraEdit.
      • Open the found file.
      • Run the macro on the opened file.
      • Save the file.
      • Exit UltraEdit.
      That is a very inefficient approach.

      Better would be doing the file reformatting task without using a PowerShell script at all and starting UltraEdit only once:
      • Start UltraEdit with just the macro containing just ReplInFiles commands to reformat all files in that directory matching a file name wildcard pattern.
      • Start UltraEdit with just the macro written for running a FindInFiles with an empty search string to get into a results file the list of file names with full path matching file name pattern *.edi and then the macro opens, reformats, saves and closes each file in the list before finally closing the results file without saving it and exiting resulting in exiting also UltraEdit. See for example Run Macro on all files within folder.
      • Start UltraEdit with

        Code: Select all

        "%ProgramFiles%\IDM Computer Solutions\UltraEdit\uedit64.exe" /fni "\\pubtech\users\pubtechops2\My Documents\UltraEdit Files\TEST FILES MOVE N9\*.edi" /M,E="C:\SCRIPTS\Move N9.mac"
        which should result in opening all *.edi files by UltraEdit found in the directory and the macro is written to run once on each opened file.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Mar 08, 2017#3

        Thank you.
        Your technique does sound more efficient.
        I'll try that next as that sounds like a good improvement.  
        Starting UltraEdit once and then looping through my files should run faster.

        In the short term I did get the way I was trying to do it to work.
        Technical support (thanks Josh) helped me solve my original issue of getting UltraEdit to behave when started from PowerShell.
        The mix of forward and backward slashes needed to be "quoted" to avoid issues.

        To share with anyone else that may look in future, here is the PowerShell that works.

        Code: Select all

        $In = "\\pubtech\users\pubtechops2\My Documents\UltraEdit Files\TEST FILES MOVE N9"
        $Macro = '/m,e="C:\SCRIPTS\IPG_PROD\BND\Move N9.mac" '
        
        # There is an Archive subfolder, we don't want to go into that folder, so it is excluded.
        
        Get-ChildItem -Path $In -recurse -Include *.edi | ? { $_.FullName -inotmatch 'archive' } |
        Foreach-Object {
            $_.FullName
        #
        # Build the full argument object. The spaces are important.
        # The forward and backward slashes can cause issues so create one argument object
        # to use on the command line
        #
            $arg = "/fni "+$_.FullName+" "+$Macro
            &uedit64  $arg | out-null
        }
        exit