Game Development Community

Delete a file

by Bruno · in Torque Game Builder · 08/31/2008 (3:44 am) · 7 replies

Hi,

Is there a way to delete a file from a script ?

After closing the file,
FR.Close();

I tried
FR.Delete();

Doens't do nothing, but does not give an error either.

thanks,
Bruno

#1
08/31/2008 (3:53 am)
You need to physically delete the file. In your case, you have just deleted the fileObject streaming the contents of the file.

I believe the function is:
fileDelete(expandFileName("game/myFile.ext"));
#2
08/31/2008 (4:04 am)
Thanks Phillip,

Doens't seem to do anything.,
I tried with the expandFileName and without it (i tought expandFileName was before Torque 1.7 ) ?
Any idea on what could be the problem ?
I can open, read or write to that same folder, so it's not a path problem.

thanks again,
Bruno
#3
08/31/2008 (4:11 am)
Are you familiar with the file changes in 1.6+? tdn.garagegames.com/wiki/TGB/FileIO

Try and determine whether the TGB thinks the file exists or not.

echo ("IsFile:" SPC isFile(expandFileName(...)));

You do need expandFileName unless you're refering to an absolute path, i.e. "C:\MyGames\..."
#4
08/31/2008 (4:19 am)
Yes, i'm familiar with the changes.

Let me show what i'm doing :

%filename = "game/savegame/test.player";
%yes = FR.OpenForRead(%filename);

That code works fine.

echo ("IsFile:" SPC isFile(expandFileName(%filename)));

IsFile is returning 1, so, it's working fine too.

fileDelete(expandFileName(%filename));

Nothing happens there. The line runs fine, no errors, but no file is deleted.
#5
08/31/2008 (5:53 am)
Well, made some more experiments, and i'm really confused.

This way, the file is deleted :

fileDelete(expandFileName("C:\Documents and Settings\Bruno\Application Data\x\test\game\savegame\test.player"));

Torque, also reports that it can find the file, in both this situations :
echo ("IsFile:" SPC isFile(expandFileName(%filename)));
                echo ("IsFile2:" SPC isFile(%filename));

However, it refuses to delete the damn file
fileDelete(expandFileName(%filename));
                fileDelete(%filename);

filename is
%filename = "game/savegame/test.player";


why, oh whhyyyy ?
what am i doing wrong here... ?
#6
08/31/2008 (7:23 am)
So,

It seems this is a known bug.

http://www.garagegames.com/mg/forums/result.thread.php?qt=74254

fileDelete doens't work in Torque..., great
#7
08/31/2008 (12:45 pm)
It works every time that I used it! Are you sure it isn't deleting the file that resides in your AppData folder?