Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Jim Reed on Thu 30/07/2009 13:16:59

Title: Deleting a contents of .txt file, how to do it?
Post by: Jim Reed on Thu 30/07/2009 13:16:59
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
Title: Re: Deleting a contents of .txt file, how to do it?
Post by: RickJ on Thu 30/07/2009 13:23:06
Just open the file, write a null character, and close the file.   
Title: Re: Deleting a contents of .txt file, how to do it?
Post by: Jim Reed on Thu 30/07/2009 13:38:53
I'm so dumb. =D
Thanks.
Title: Re: Deleting a contents of .txt file, how to do it?
Post by: monkey0506 on Fri 31/07/2009 05:05:51
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:

File *f = File.Open("temp.tmp", eFileWrite);
if (f != null) f.Close();
Title: Re: Deleting a contents of .txt file, how to do it?
Post by: Dualnames on Sat 01/08/2009 15:08:01
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
Title: Re: Deleting a contents of .txt file, how to do it? [solved]
Post by: Jim Reed on Sat 01/08/2009 18:15:23
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.
Title: Re: Deleting a contents of .txt file, how to do it?
Post by: monkey0506 on Sun 02/08/2009 01:30:21
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? :=
Title: Re: Deleting a contents of .txt file, how to do it?
Post by: Jim Reed on Sun 02/08/2009 11:22:47
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