change word1 to word2 in folder?

Started by: vinc252 voices2 posts

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://emeditor.wpengine.com/help/macro/const/const_encoding.htm
nSrcEncoding = eeEncodingSystemDefault;

// destination file encoding
// available encodings can be found at http://emeditor.wpengine.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 );

}
}
}
}

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 :-)

2 posts in this topic