Jump to content

Command to erase?


Recommended Posts

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

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 by Nahuel
Link to comment
Share on other sites

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

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

  • 1 year later...

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.

James

Smith

401 Adams Ave.

Montgomery

36104

Harry

Brown

402 Adams Ave.

Montgomery

36104

My 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:

Harry

Brown

402 Adams Ave.

Montgomery

36104

This way the bot can loop again and read the first 5 lines again, etc.

Thanks!

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