ReplaceInFiles Method (Editor Object)

Replaces text in multiple files.

[JavaScript]

nFound = editor.ReplaceInFiles( strFind, strReplace, strPath, nFlags, [ nEncoding, [ strFilesToIgnore, [ strBackupPath, [ nExFlags, [ nLimit ] ] ] ] ] );

[VBScript]

nFound = editor.ReplaceInFiles strFind, strReplace, strPath, nFlags, [ nEncoding, [ strFilesToIgnore, [ strBackupPath, [ nExFlags, [ nLimit ] ] ] ] ]

Parameters

strFind

Specifies a string to search for.

strReplace

Specifies a string to replace with.

strPath

Specifies a path to search from. It can include wild cards such as * and ?.

nFlags

Specifies a combination of the following values.

eeFindRecursive

Searches in subfolders of the specified path.

eeFindReplaceCase

Matches cases.

eeFindReplaceEscSeq

Uses escape sequences. Cannot combine with eeFindReplaceRegExp.

eeFindReplaceIgnoreFiles

Ignores the files or folders specified by strFilesToIgnore.

eeFindReplaceOnlyWord

Searches only words.

eeFindReplaceRegExp

Uses a regular expression. Cannot combine with eeFindReplaceEscSeq.

eeOpenDetectAll

Detects all encodings.

eeOpenDetectCharset

Detects HTML/XML Charset.

eeOpenDetectUnicode

Detects Unicode signature (BOM).

eeOpenDetectUTF8

Detects UTF-8.

eeReplaceBackup

Saves the backups. Cannot combine with eeReplaceKeepOpen.

eeReplaceKeepOpen

Keeps the modified files open. Cannot combine with eeReplaceBackup.

nEncoding

Selects from the Encoding Constants, or specify any code page used in the Windows Operating System. If 0 is specified or omitted, the encoding specified in the configuration properties associated with the searched file name will be used.

strFilesToIgnore

If nFlags  includes eeFindReplaceIgnoreFiles, specifies the file or folder names to ignore. It can include wild cards such as * and ?. To specify multiple files, use semicolons (;) to separate them.

strBackupPath

Specifies the backup folder if nFlags  specifies eeReplaceBackup.

nExFlags

Specifies a combination of the following values. However, only one of eeExFindRegexBoost, eeExFindRegexOnigmo, and eeExFindRegexOnigmoPerl can be specified. If none of them is specified, the default regular expression engine is used.

eeExFindFuzzy

Uses fuzzy matching.

eeExFindNumberRange

Matches a number range expression. This flag cannot be combined with eeFindReplaceEscSeq or eeFindReplaceRegExp.

eeExFindRegexBoost

Uses Boost.Regex as the regular expression engine.

eeExFindRegexOnigmo

Uses Onigmo as the regular expression engine, using the Ruby syntax.

eeExFindRegexOnigmoPerl

Uses Onigmo as the regular expression engine, using the Perl syntax.

nLimit

EmEditor stops searching files when the number of matches reaches this number. If 0 is specified, EmEditor does not stop searching files.

Return Values

The return value is the total number of replaced strings in all the searched files.

Remarks

This action cannot be undone unless nFlags  specifies eeReplaceKeepOpen. It is recommended to specify eeReplaceBackup as nFlags  and saves backups. If the same file name exists in the backup folder, the new backup will overwrite the old file.

Version

Supported on EmEditor Professional Version 4.02 or later.