Burgs Posted June 10, 2008 Share Posted June 10, 2008 Greetings, Is there a command available to "erase" the contents of a file? I simply want to write a line or lines to a .txt file and then later erase it so the file is "empty". However I do not wish to delete the .txt file...possible? Thanks in advance. Link to comment Share on other sites More sharing options...
Nahuel Posted June 10, 2008 Share Posted June 10, 2008 (edited) Look in the help file for FileOpen(). You can specify to open the file in Write Mode. This will erase all previous content. Something like: $file = FileOpen("test.txt", 2);2=write mode FileWrite($file,"");not sure if this is nessesary. Try. FileClose($file) Edited June 10, 2008 by Nahuel Link to comment Share on other sites More sharing options...
Airwolf Posted June 10, 2008 Share Posted June 10, 2008 (edited) #include <file.au3> $file = "filename.txt" $CountLines = _FileCountLines($file) For $x = 1 To $CountLines _FileWriteToLine($file, $x, "", 1) NextoÝ÷ ØêÚºÚ"µÍÌÍÙ[HH[SÜ[ ][ÝÙ[[[YK ][ÝËB[PÛÜÙJ ÌÍÙ[J Edited June 10, 2008 by Airwolf123 Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt Link to comment Share on other sites More sharing options...
JellyFish666 Posted June 10, 2008 Share Posted June 10, 2008 Greetings, Is there a command available to "erase" the contents of a file? I simply want to write a line or lines to a .txt file and then later erase it so the file is "empty". However I do not wish to delete the .txt file...possible? Thanks in advance. something basic like this should get you off to a good start I hope, look theses functions up in the helpfile and you'll really get the hang of it hopefully. Global $Text[3] $Text[1] = "Hello" $Text[2] = "I hope this is what your looking for..." $Path = @ScriptDir & "\test.txt" FileWrite($Path , "") FileOpen($Path , 2) FileWrite($Path , $Text[1] & @CRLF & $Text[2]) FileClose($Path) Link to comment Share on other sites More sharing options...
Burgs Posted June 10, 2008 Author Share Posted June 10, 2008 Thank you everybody! Good info to know for the future. Link to comment Share on other sites More sharing options...
miketh2005 Posted May 6, 2010 Share Posted May 6, 2010 Hello. I have a similar problem, and the suggestions above don't work for me, because that line is still there and it is blank. It makes the line blank, but I need it to erase the line completely and bring up the info below. Eg.JamesSmith401 Adams Ave.Montgomery 36104HarryBrown402 Adams Ave.Montgomery 36104My bot reads the first 5 lines. I want it to erase the first 5 lines after it is done reading them to bring up the info below it to where it was before. Eg. After the erase the file will look like this:HarryBrown402 Adams Ave.Montgomery 36104This way the bot can loop again and read the first 5 lines again, etc.Thanks! 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