I suppose, your script is different to what you have posted because this script does not really make sense.
There is the Replace in Files command to replace a string in many files in a directory or even directory tree. This command is also available as scripting command if this replace in files must be done in more or less regular intervals and not only once.
If the files contain the string to replace more than once and just the first occurrence should be replaced in every file, it could be nevertheless possible to use a tagged Perl regular expression replace to replace just first occurrence, if the files are small, i.h. < 32 KB.
But if you really need to run a script code on all *.php files within a folder, you need my script function GetListOfFiles
copied into your script and additionally following script code:
- Code: Select all
// Select the list of file names and load them into an array of strings.
var asFiles = UltraEdit.activeDocument.selection.split("\r\n");
// Remove the last string from the array which is an empty string
// because of the line termination at end of the file names list.
// Close the Find in Files results file without saving it.
// Open one file after the other for the modification.
for (var nFile = 0; nFile < asFiles.length; nFile++)
// Open the next file to modify.
// Insert here your script code to modify current file.
// Close the file with saving the modification.
There are other methods, but this is the best one if the script has to do it several times. The path of the directory must be adapted in the first line of this code.
Attention: None of the *.php files in the specified directory should be already opened in UltraEdit on execution of this script because in this case open command does nothing and the current file is modified, saved and closed. I don't have added the code for checking if a file to open is already opened in UltraEdit which would make this script slower.
And don't forget to read the comments of the function GetListOfFiles which must be embedded, especially when not using English version of UltraEdit because in this case 2 string variable values must be adapted to your localized version of UltraEdit in code of GetListOfFiles.