emeditor

Emeditor: run a macro for all file inside a folder?


How to run a (previously recorded) macro for all files inside a folder ?

Example : I have recorded a macro that is working correctly for an opened html file. I have saved the macro as "test.jsee". I have a folder in my computer named "C:\folder_with_files". It is full of html files. How to run "test.jsee" for all files inside the folder "C:\folder_with_files" ?

ps: same question if many subfolders contains html files inside the main big folder "C:\folder_with_files" ?

pps: my idea is that Emeditor opens one file, run the macro, close the file (I have already saved the updated file in my macro) and do the same for the next file.


Solution

  • There are two ways to accomplish your task.

    1. Select Run with Temporary Options on the Macros menu. Select the macro, set the Run the macro against each opened document option, add (or drag and drop) files or folders to the list, and set the Save and close each document after running the macro if necessary.

    Or

    1. Select Advanced Open on the File menu. Set the Run a macro against each opened document, select the macro, click the Select Files to Open... button to select all files you want to open.

    Or

    1. Run a macro using JScript with Scripting.FileSystemObject. Your old macro should be written as a function (in this case, MyFunc):
    #language = "JScript"
    
    function MyFunc( sFileName )   // macro function to call
    {
        document.writeln( sFileName );  // Replace this with what you want to do with sFileName
    }
    
    sFolder = "C:\\folder_with_files";   // a folder you want to search
    
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFolder(sFolder);
    fc = new Enumerator(f.files);
    for (; !fc.atEnd(); fc.moveNext()) {
        MyFunc( fc.item().name );
    }
    

    If you can't see these commands, please make sure you are using the newest version of EmEditor Professional.