Delai Posted September 16, 2006 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
Moderators SmOke_N Posted September 16, 2006 Moderators 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.
dabus Posted September 16, 2006 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.
Delai Posted September 16, 2006 Author Posted September 16, 2006 I will try it but first i must fix the fact there is no change in the file
Delai Posted September 16, 2006 Author 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
dabus Posted September 17, 2006 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.
randallc Posted September 17, 2006 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
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