mrmacadamia Posted October 9, 2013 Share Posted October 9, 2013 Hi, it's been awhile since i last coding. anyway, i have a list in a file in animal.txt. e.g cat dog chicken mouse then i want to use that list to replace string "something" in multiple files. e.g in mypet-1.txt i have a something. mypet-2.txt i have a something. mypet-3.txt i have a something. mypet-4.txt i have a something. Can somebody can come out with a simple script? Link to comment Share on other sites More sharing options...
blckpythn Posted October 9, 2013 Share Posted October 9, 2013 (edited) Arrays and For loops. #include <File.au3> Global $array Global $array2 _FileReadToArray("C:\users\%username%\desktop\animal.txt", $array) _FileReadToArray("C:\users\%username%\desktop\file2.txt", $array2) For $i = 1 To $array[0] _ReplaceStringInFile($array2[$i], "something", $array[$i]) Next In this example file2.txt has: C:\users\%username%\desktop\mypet-1.txt C:\users\%username%\desktop\mypet-2.txt C:\users\%username%\desktop\mypet-3.txt C:\users\%username%\desktop\mypet-4.txt If you want to change the text for all txt files in a directory until you run out of words in your animals.txt you can replace: _FileReadToArray("C:users%username%desktopfile2.txt", $array2) With $array2 = _FileListToArray("C:path-to-folder-with-myfiles") And change the ReplaceString function to_ReplaceStringInFile("C:path-to-folder-with-myfiles" & $array2[$i], "something", $array[$i]) *Edited for a few revisions after I reread replacing the string instead of simply writing it to the file. Edited October 10, 2013 by blckpythn Link to comment Share on other sites More sharing options...
mrmacadamia Posted October 9, 2013 Author Share Posted October 9, 2013 You're the man! My mind is clearer now. except that : ReplaceString function to_ReplaceStringInFile("C:\path-to-folder-with-myfiles\" & $array[$i], "something", $array[$i]) to ReplaceString function to_ReplaceStringInFile("C:\path-to-folder-with-myfiles\" & $array2[$i], "something", $array[$i]) Anyway thanks. Link to comment Share on other sites More sharing options...
blckpythn Posted October 10, 2013 Share Posted October 10, 2013 The FileListToArray method doesn't return the whole path, only the filenames. So unlike reading a file with the full paths, you would have to specify the path leading up to the filenames. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now