Deleting a contents of .txt file, how to do it?

Started by Jim Reed, Thu 30/07/2009 13:16:59

Previous topic - Next topic

Jim Reed

Is it possible to open a .txt file, check if it is empty, if not, delete everything in it?
Is this a question for the BTQ forum?
What's the meaning of life?
Ahh, questions...questions... =D

RickJ

Just open the file, write a null character, and close the file.   


monkey0506

Quote from: RickJ on Thu 30/07/2009 13:23:06
Just open the file, write a null character, and close the file.   

If you open the file in eFileWrite mode doesn't that automatically truncate the file to 0 bytes anyway? So just:

Code: ags
File *f = File.Open("temp.tmp", eFileWrite);
if (f != null) f.Close();

Dualnames

Is it possible to open a .txt file, check if it is empty, if not, delete everything in it?

Of course. You can handle files in 3 ways/modes
Append is to add data to a file (without replacing content)
Write is to clear file contents and add your data
Read is to read data from a file

Is this a question for the BTQ forum?

Yes

What's the meaning of life?

42
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Jim Reed

Yes, now after I tried it, writing (not apending) anything to a file deletes file's contents, before writing to it.

42? Nope, I tried, it's not dividable by yellow.

Ok, maybe on tuesdays it is.

monkey0506

Exactly. As Dual said:

eFileWrite will create or overwrite the file.

eFileAppend will create the file, or if it exists, append data to the end of it.

eFileRead will open the file at the beginning to read the contents.

As far as 42, what makes you so much smarter than Deep Thought, eh? :=

Jim Reed

Yes, looks like I did actually need to post this into the BTQ forum. My bad. :-[
And yes, I am smarter than Deep Thought...
My mum said I was!
I love my mum!
She gives me candy sometimes and we play and she is so funny and tells stories and makes me pancakes sometimes!  ;D


SMF spam blocked by CleanTalk