EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     change word1 to word2 in folder?
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
Cirillo
Posted on: 8/10/2010 8:06 am
Not too shy to talk
Joined: 7/2/2010
From:
Posts: 21
Re: change word1 to word2 in folder?
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
vinc25
Posted on: 8/7/2010 8:18 am
Just popping in
Joined: 8/7/2010
From:
Posts: 3
change word1 to word2 in folder?
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 );
               
           }
       }
    }
}

Threaded | Oldest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文