Jump to content

filewrite and stringreplace


Cap0
 Share

Recommended Posts

how would i do filewrite and stringreplace?

if(stringinstr($params[4],"/nick\")) Then
$read = FileRead("file.txt",FileGetSize("file.txt"))
                            FileWrite("reply.txt",StringReplace($read,"xx",xx))
Endif

i put this at the start of the script but it writes a lot of times..

Link to comment
Share on other sites

  • Developers

how would i do filewrite and stringreplace?

if(stringinstr($params[4],"/nick\")) Then
$read = FileRead("file.txt",FileGetSize("file.txt"))
                            FileWrite("reply.txt",StringReplace($read,"xx",xx))
Endif

i put this at the start of the script but it writes a lot of times..

It will append it to the end of the file in this way.

You need to delete file "file.txt" before doing the FileWrite()

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Still having trouble :)

if(stringinstr($fileread,"xx")) Then
    Filedelete("re.txt")
                            FileWrite("re.txt",StringReplace($fileread,"xx","yy"))
Endif

it doesn't replace

Edited by Cap0
Link to comment
Share on other sites

  • Moderators

bump

How about providing a real example... like the rest of $fileread. I'm amazed at how little those that ask questions want to provide those of us that generally answer them sometimes. The endless bumps, or un-answered questions stem from lack of information generally.

$hFileName = "FulPathToFile\FileName.txt"
$sString = FileRead($hFileName)
If StringInString($sString, 'xyz') Then
    FileClose(FileOpen($hFileName, 2))
    FileWrite($hFileName, StringReplace($sString, 'xyz', 'abc'))
EndIf

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

how would i do filewrite and stringreplace?

if(stringinstr($params[4],"/nick\")) Then
$read = FileRead("file.txt",FileGetSize("file.txt"))
                            FileWrite("reply.txt",StringReplace($read,"xx",xx))
Endif

i put this at the start of the script but it writes a lot of times..

just use _ReplaceStringInFile()

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

How about providing a real example... like the rest of $fileread.

$read = FileRead("file.txt",FileGetSize("file.txt"))
as posted above in my first post..

thanks anyway, but i've found an easier solution. _ReplaceStringInFile();

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...