Game Development Community

Can't Delete Files from the Home Directory.

by Orion the Hunter · in Torque Game Builder · 09/10/2013 (6:56 pm) · 2 replies

Yes, it's me again. I've got another problem...

I'm trying to make a code that will delete save files. The problem is that it won't delete things from the Home directory in my Library folder. It should be working because I've got this code:

function deleteGame(%folderName, %level, %inv, %misc, %close)
{

echo("Foldername is... " @ %foldername);
%file = new FileObject();
%file1 = new FileObject();
%file2 = new FileObject();
%file3 = new FileObject();

    if(%file.openForRead("~/data/saves/" @ %folderName @ ".hdsdat"))
    {
    if(%level)
    {
    fileDelete("~/data/saves/" @ %folderName @ "/LevelData.hdsave");
    }
    }
    else
    {
    error("Failed to delete the level data!");
    }

    if(%file1.openForRead("~/data/saves/" @ %folderName @ "/LevelData.hdsave"))
    {
    if(%level)
    {
    fileDelete("~/data/saves/" @ %folderName @ "/LevelData.hdsave");
    }
    }
    else
    {
    error("Failed to delete the level data!");
    }

    if(%file2.openForRead("~/data/saves/" @ %folderName @ "/InventoryData.hdsave"))
    {
    if(%inv)
    {
    fileDelete("~/data/saves/" @ %folderName @ "/InventoryData.hdsave");
    }
    }
    else
    {
    error("Failed to delete the inventory data!");
    }

    if(%file3.openForRead("~/data/saves/" @ %folderName @ "/MiscData.hdsave"))
    {
    if(%misc)
    {
    fileDelete("~/data/saves/" @ %folderName @ "/MiscData.hdsave");
    }
    }
    else
    {
    error("Failed to delete the misc data!");
    }

    %file1.close();
    %file1.delete();

    if(%close)
    {
    canvas.popDialog(LoadGui);
    }
    else
    {
    canvas.popdialog(loadgui);
    canvas.schedule(32, "pushdialog", "loadGui");
    }
}

~/ should signify "(Me)/Library/(My Company)/(My game)/" but it won't. I'm using a Mac, so please keep in mind that getUserHomeDirectory doesn't work...

Thanks for the help!

#1
09/12/2013 (8:49 am)
"~/" is the game executable directory. Or, on older versions, the game's "root" directory (I believe it was the location housing the "main" main.cs file).
#2
09/24/2013 (6:38 am)
And you should surround that with expandPath().