Jump to content
Sign in to follow this  
Delai

Opem replace and save as

Recommended Posts

Delai

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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
dabus

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.

Share this post


Link to post
Share on other sites
Delai

I will try it but first i must fix the fact there is no change in the file

Share this post


Link to post
Share on other sites
Delai

@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

Share this post


Link to post
Share on other sites
dabus

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.

Share this post


Link to post
Share on other sites
randallc

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

Share this post


Link to post
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
Sign in to follow this  

×