Jump to content

Opem replace and save as


Delai
 Share

Recommended Posts

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 successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 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 handle

FileClose($search)

Edited by Delai
Link to comment
Share on other sites

  • Moderators

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

@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 by Delai
Link to comment
Share on other sites

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 by randallc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...