ID:2044777
 
(See the best response by GreatPirateEra.)
For something I'm working on, I'm storing the file path of a savefile into a list saved onto a savefile for more global settings, then loading stuff from the non-global savefile when needed, i.e.

MakeNPC( name as text )
var/filepath = "npcs/npc_[name].sav"

var/savefile/F = New( filepath )

F["owner"] << usr.ckey
etc.

global.npc_saves += filepath

LoadNPCs()
for( var/dir in global.npc_saves )
if( file(dir) )
etc.
else
global.npc_saves -= dir


... But, using this method, file() returns true regardless of if the savefile exists or not.

I've tried various other methods, ( isfile() always returns false instead, etc. ) and eventually found something that did work, but it involves reading a value from the savefile, which ends up creating a blank savefile if the file doesn't exist. While this does work, because a blank savefile doesn't have the value I'm checking for, it feels like this solution could be confusing for the end user, as suddenly a file that they deleted suddenly "sprang back up", even if now 0 bytes in size. And I can't seem to figure out if I can delete the file from BYOND, either.

Am I just approaching this from the wrong way, or am I just stuck with this if I want to use this method?
Best response
if(fexists(F))
//load savefile
Ah, that did it. Thanks!
That should be fexists(file_path) not fexists(F).
In response to Nadrew
Well, he's referencing his file path with F already
In the code he posted the only reference to 'F' is a savefile, which doesn't really work when passed to fexists(), looking at it again it should be "fexists(dir)" =P