Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8824

    vinc25
    Member

    Hello!

    I found a code in lib that can convert encoding in a specified folder.
    I want to run a simple task: changing “word1” to “word2” for all .txt files in folder “C:Test”.

    document.selection.Replace("word1","word2",eeFindNext | eeFindReplaceEscSeq | eeReplaceAll);

    What do I need to change to accomplish this?

    // This macro converts the encoding of all files (of specified file extension) in the specified folder to a specified encoding.
    // Warning: this macro cannot undo the changes. Please make backup of your files before you run!
    //
    // folder to search
    // remember to escape with another .
    sFolder = "C:Test";

    // file extension (must begin with a period (.) )
    sExt = ".txt";

    // source file encoding
    // available encodings can be found at http://www.emeditor.com/help/macro/const/const_encoding.htm
    nSrcEncoding = eeEncodingSystemDefault;

    // destination file encoding
    // available encodings can be found at http://www.emeditor.com/help/macro/const/const_encoding.htm
    nDestEncoding = eeEncodingUTF8;

    // destination file Unicode Signature (BOM), true or false.
    bUnicodeSignature = false;

    if( sFolder != "" ){
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFolder(sFolder);
    fc = new Enumerator(f.files);
    sItem = "";
    for (; !fc.atEnd(); fc.moveNext()) {
    n = fc.item().name.lastIndexOf(".");
    if( n != -1 ){
    if( fc.item().name.slice( n ) == sExt ){
    sPath = sFolder + "" + fc.item().name;
    try {
    editor.OpenFile( sPath, nSrcEncoding, eeOpenDetectUnicode );
    }
    catch(e){
    break;
    }
    document.Encoding = nDestEncoding;
    document.UnicodeSignature = bUnicodeSignature;
    document.Save( sPath );

    }
    }
    }
    }

    #8834

    Cirillo
    Participant

    Hello!
    You don’t really need a macro to run this task.
    All you need is Menu > Search > Replace in Files.
    More info in EmEditor Help-How to…-Search-Replace in Files.
    GL :-)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.