home *** CD-ROM | disk | FTP | other *** search
- !!script
- // Copyright ⌐ 1997-1999 - Modelworks Software
- // @Modified build 287 cm19990410 - added support for the new Replace In Files dialog
-
- /**
- @Tool: replaceInFiles~replaces a findWhat expression with a replaceWith
- value in all files included in the selected directory. All changes made to
- documents are listed in the output panel.
- @EndTool:
- @Summary: replaceInFiles~does a search and replace in a selected directory
- */
-
- var gOutput = getOutput();
-
- function DoCommand()
- {
- if (chooseReplaceInFilesParameters("Replace in files"))
- {
- saveAll();
-
- var findParameters = getGlobal("FindParameters", null);
-
- gOutput.clear();
- gOutput.writeLine("Searching for: '" +
- findParameters.findWhat +
- "', Replacing with: '" + findParameters.replaceWith + "'");
-
- var files = getDirectoryFiles(findParameters.searchPath, findParameters.fileTypes,
- findParameters.searchSubFolders);
- if (files)
- {
- var findData = null;
- var position = files.getHeadPosition();
- while (position.valid)
- {
- var file = files.getNext(position);
- var editor = file.open(false);
- if (editor)
- {
- gOutput.writeLine("Searching in: " + file.path);
-
- var lineIndex = -1;
- var fileName = editor.path;
-
- var findData = editor.findFirst(findParameters.findWhat, 0, 0, true, findParameters.caseSensitive,
- findParameters.regularExpression, findParameters.replaceWith);
-
- while (findData && findData.found)
- {
- editor.replace(findData.getReplaceValue(), findData);
-
- var range = findData.range;
-
- // Only print out one message per line
- if (lineIndex != range.startLineIndex)
- {
- lineIndex = range.startLineIndex;
- gOutput.writeMessage(fileName, lineIndex, editor.copy(lineIndex));
- }
-
- editor.findNext(findData);
- }
- if (!editor.visible)
- {
- editor.close();
- }
- }
- }
- }
- gOutput.writeLine("Replace in directory completed");
- }
- }
-
- !!/script
-
-