Sign in to follow this  
Followers 0
zoub99

how to use ReplaceStringInFile

6 posts in this topic

hi,

i have a txt file (ipstation.txt) who contains this chain:

192.192.192.192;255.255.255.255;192.168.0.1

i want to replace the string "192.192.192.192" by "192.168.0.2"

my script

;=======================================================

; creation du fichier ipstation.txt en ecriture

$FICHIPSTATION = FileOpen("C:\temp\clone\ipstation.txt",2)

If $FICHIPCONFIG = -1 Then

MsgBox(0, "Erreur", "Il n'a pas été possible de créer le fichier!")

Exit

EndIf

$IP="192.192.192.192"

ReplaceStringInFile ($FICHIPSTATION,$IP,$IPPC)

;=======================================================

$IPPC is the chain "192.168.0.2"

but it doesn't work

thanks for your help

zoub99

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

1. FileOpen('FileName', 2) Deletes the current files content :whistle:

2. You don't need to do that with ReplaceStringInFile. (Also the UDF needs an underscore in front of it)

#include <File.au3>
_ReplaceStringInFile ("C:\temp\clone\ipstation.txt", '192.192.192.192', '192.168.0.2')
Is all you need. Edited by SmOke_N

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

Tsk tsk, Smoke, you need to heed your own advice. You forgot the underscore in your [code] example. :whistle:

Share this post


Link to post
Share on other sites

Tsk tsk, Smoke, you need to heed your own advice. You forgot the underscore in your [code] example. :)

:whistle: No doubt I did!! I had an error in posting ... the code came out jumbled so I "fixed" it (yeah... some fix!)

Thanks Saunders - Editing it now.


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

thank's for your answers........but it doesn't work's :whistle:

my new script (is name is "recup adresse mac.au3")

#include <File.au3>

ReplaceStringInFile ("C:\temp\clone\ipstation.txt", '192.192.192.192', '192.168.0.2')

is the line "#include <File.au3>" important for ReplaceStringInFile ?

in that case can i put in the script "#include recup adress mac.au3"

sorry for my stupid questions but i begin with autoit

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

thank's for your answers........but it doesn't work's :whistle:

my new script (is name is "recup adresse mac.au3")

#include <File.au3>

ReplaceStringInFile ("C:\temp\clone\ipstation.txt", '192.192.192.192', '192.168.0.2')

is the line "#include <File.au3>" important for ReplaceStringInFile ?

in that case can i put in the script "#include recup adress mac.au3"

sorry for my stupid questions but i begin with autoit

Yes, File.au3 is neceassey since the _ReplaceStringInFile() function is a user defined function that is stored in file.au3

The code above didn't work because you removed the underscore( "_" ) from be beginning of the function. A user defined function has an underscore in front of it to let the programmer know that the function is not a native autoit function.

#include <File.au3>
_ReplaceStringInFile ("C:\temp\clone\ipstation.txt", '192.192.192.192', '192.168.0.2')

Try that to the character^.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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  
Followers 0