Jump to content

Recommended Posts

Posted

I have look at StringReplace but im not sure how to make it work for a text file. I want to find a certain string in a text file and then replace it.

www.SecurityDistro.com

Posted

Look in the help at the example for FileReadLine. Just loop through the file, read each line, replace the string if necessary and write to a temp file. When done, delete the original file and rename the temp one.

Auto3Lib: A library of over 1200 functions for AutoIt
Posted

Look in the help at the example for FileReadLine. Just loop through the file, read each line, replace the string if necessary and write to a temp file. When done, delete the original file and rename the temp one.

That is similar to what I tried to do. The problem is that for some reason I have always had trouble getting AutoIt to delete or rename external files correctly. The very last line in my code is the delete call and it still will not delete. I also have a call before that to close the file just to make sure it is ready for deletion.

www.SecurityDistro.com

Posted

Look at _FileReadToArray and _FileWriteFromArray.

You would read the file in, loop thru the array, replace the text and write back out to the same file.

I will take a look at that. What do you think of the problem with AutoIt deleting files?

www.SecurityDistro.com

Posted

What do you think of the problem with AutoIt deleting files?

Are you closing the file before trying to delete it? Is there another process that has the file open?
Auto3Lib: A library of over 1200 functions for AutoIt
Posted

Are you closing the file before trying to delete it? Is there another process that has the file open?

I wrote a test program just to see if there is something I am doing wrong. My guess is that there is.

FileOpen("file.txt",1)

FileWrite("file.txt","check me out")

FileClose("file.txt")

FileDelete("file.txt")

Running this does not delete the file off of my box.

www.SecurityDistro.com

Posted

It appears that AutoIt does not like me hardcoding the file name. I wrote the following and it worked.

$file = FileOpen("file.txt",1)

FileWrite($file,"check me out")

FileClose($file)

FileDelete("file.txt")

www.SecurityDistro.com

  • Moderators
Posted

It appears that AutoIt does not like me hardcoding the file name. I wrote the following and it worked.

$file = FileOpen("file.txt",1)

FileWrite($file,"check me out")

FileClose($file)

FileDelete("file.txt")

It had nothing to do with "Hard coding", FileClose("file.txt") << was wrong. You need to use the "handle" from FileOpen() to close it, which you did in your last example. Just thought you'd like to know why the last one worked, and the other didn't.

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.

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
  • Recently Browsing   0 members

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