Checking if a certain file exists

Started by Ubel, Thu 18/05/2006 16:10:08

Previous topic - Next topic

Ubel

I'm making a save GUI. I need to know how I can check if a certain agssave-file already exists. For example, let's say I want to check if "agssave.001"-file exists. What kind of scripting should I use for this?

This is because I want to make sure my save GUI doesn't save over any agssave file if it already exists in the compiled folder.

I hope you know what I mean. Thanks. :)

strazer

Code: ags

  File *thefile = File.Open("agssave.001", eFileRead);
  if (thefile == null) {
    Display("Error opening file."); // i.e. file probably doesn't exist
  }
  else {
    // do stuff
    thefile.Close();
  }

Ubel

Ah yes, I thought it would be done in a similiar way with File.Open. I just didn't know how exactly this could be done, but apparently it's very simple. Thanks for the quick answer.


Dr. Scary

Or you could use the even simpler method that the manual suggests:

Quote
GetSaveSlotDescription
(Formerly known as global function GetSaveSlotDescription, which is now obsolete)

static String Game.GetSaveSlotDescription(int slot)
Gets the text description of save game slot SLOT.
If the slot number provided does not exist, returns null.

SMF spam blocked by CleanTalk