Delai Posted September 16, 2006 Share Posted September 16, 2006 (edited) Hi men.I want to open a file, replace a string and save as with onother name. the problem when i find the file, i can´t replace the string. here is my script:; Shows the filenames of all files in the current directory.$search = FileFindFirstFile("Video.*") ; Check if the search was successfulIf $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitEndIfWhile 1 $file = FileFindNextFile($search) If @error Then ExitLoop $Avi = StringSplit( $file , "." ); MsgBox(4096, "File:", $Avi[2]) $Open = Run('Notepad.exe ".\Scripts\Video-Plantilla.avs"')!!! here i want to change "plantilla" with "$Avi[2]", but it does not change anything!!! StringReplace($Open, "Plantilla", "$Avi[2]")!!! here i want to save it as another name and leave the original intact, but i dont know if must i use FileSaveDialog or FileMove!!!!WEnd; Close the search handleFileClose($search) Edited September 16, 2006 by Delai Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 16, 2006 Moderators Share Posted September 16, 2006 If you know what you want to name it, and it's the same file that you want to rename, then you can use FileMove(), even if it's in the same directory. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
dabus Posted September 16, 2006 Share Posted September 16, 2006 Hey man, that will never work... $Open = Run('Notepad.exe ".\Scripts\Video-Plantilla.avs"') StringReplace($Open, "Plantilla", "$Avi[2]") Have a closer look at FileOpen & FileClose. If you want a save as effect, use filecopy > fileopen > stringreplace > fileclose. Link to comment Share on other sites More sharing options...
Delai Posted September 16, 2006 Author Share Posted September 16, 2006 I will try it but first i must fix the fact there is no change in the file Link to comment Share on other sites More sharing options...
Delai Posted September 16, 2006 Author Share Posted September 16, 2006 (edited) @Dabus I have tried Fileopen but it does not work, because i have not seen the file opened $file = FileOpen(@ScriptDir & "\Scripts\Video-Plantilla.avs", 1) Edited: I have tested a simple script, bit it does not work either, there was not any change in the file. $file = FileOpen("Video-Plantilla.txt", 1) StringReplace($file, "noise", "Hola") !! here i want to replace the word "noise" woth "hola" FileClose($file) Edited September 16, 2006 by Delai Link to comment Share on other sites More sharing options...
dabus Posted September 17, 2006 Share Posted September 17, 2006 Are you sure this file you want to edit is ascii and not unicode? If it's unicode go and search the scripts and scraps to convert it. Link to comment Share on other sites More sharing options...
randallc Posted September 17, 2006 Share Posted September 17, 2006 (edited) Hi, You haven't done a fileread to a string before the replace! (only opened the file, I think) Alternatively, use "_ReplaceStringInFile" [use example in Helpfile] Best, randall Edited September 17, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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