Hi All,
I need to replace "Robert" with "Adam" in all *.txt files of a directory structure (including subfolders)
I am using the code below.
1) What parameter I need to pass in the !!! highlighted !!! row?
2) Can I do a single pass and process both *.txt and *.dat files?
I need to replace "Robert" with "Adam" in all *.txt files of a directory structure (including subfolders)
I am using the code below.
1) What parameter I need to pass in the !!! highlighted !!! row?
2) Can I do a single pass and process both *.txt and *.dat files?
Code:
for x, cFile in pairs(File.Find(SessionVar.Expand("%SamplesFolder%\\"), "*.txt", true, true)) do -- Read the contents of a text file into a string. contents = TextFile.ReadToString(File); !!!! PROBLEM HERE !!!! -- Check the error code of the last example. error = Application.GetLastError(); -- If an error occurred, display the error message. if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION); else -- Replace every occurrence of the string "Robert" with the string "Adam". new_contents = String.Replace(contents, "Robert", "Adam", true); -- Write out the modified contents of the text file. TextFile.WriteFromString("File", new_contents, false); -- Check the error code of the last example. error = Application.GetLastError(); -- If an error occurred, display the error message. if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION); end end
Comment