spyro Posted October 26, 2006 Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
PaulIA Posted October 26, 2006 Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
spyro Posted October 26, 2006 Author Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
GaryFrost Posted October 26, 2006 Share Posted October 26, 2006 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. SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
spyro Posted October 26, 2006 Author Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
PaulIA Posted October 26, 2006 Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
spyro Posted October 26, 2006 Author Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
spyro Posted October 26, 2006 Author Share Posted October 26, 2006 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 26, 2006 Moderators Share Posted October 26, 2006 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now