ID:138316
 
...and again, I need it.

Could you find it in your giving hearts to add an fexist() proc? I want to check for the existence of a certain file in the directory of the program before I allow it to run it. Otherwise I have to go through an incredibly lengthy and hacky method of storing the information of which files are available in a savefile.
Oh, file exist. I get it.

Z
On 11/4/00 12:12 pm Spuzzum wrote:
...and again, I need it.

Could you find it in your giving hearts to add an fexist() proc? I want to check for the existence of a certain file in the directory of the program before I allow it to run it. Otherwise I have to go through an incredibly lengthy and hacky method of storing the information of which files are available in a savefile.

There are a couple of easy ways to do this currently. One idea is to use the flist() proc using the file as the specifier, and then checking the number of entries returned. If 0 are returned, the file file doesn't exist. Eg:

proc/fexist(path)
var/list/L = flist(path)
return (L.len>0)
In response to Tom H.
Could you find it in your giving hearts to add an fexist() proc? I want to check for the existence of a certain file in the directory of the program before I allow it to run it. Otherwise I have to go through an incredibly lengthy and hacky method of storing the information of which files are available in a savefile.

There are a couple of easy ways to do this currently. One idea is to use the flist() proc using the file as the specifier, and then checking the number of entries returned. If 0 is returned, the file doesn't exist.

There's an flist() proc? Heh, I never even noticed that one existed... if I did I would've come up with this solution a while ago. =)


proc/fexist(path)
var/list/L = flist(path)
return (L.len>0)

Clever! I never thought of using a comparison operator to return a value. My code always looks like:

proc/fexist(path)
var/list/L = flist(path)
if(L.len > 0)
return 1
else
return 0
In response to Spuzzum
There are a couple of easy ways to do this currently. One idea is to use the flist() proc using the file as the specifier, and then checking the number of entries returned. If 0 is returned, the file doesn't exist.

There's an flist() proc? Heh, I never even noticed that one existed... if I did I would've come up with this solution a while ago. =)

Could we add an optional "files of extension .ext" filter to the flist() proc as well, to only return files with a certain extension? I don't want people to be able to request .exe's!

Something like flist("dir1/dir2/.../path",".ext") would serve me fine.
In response to Spuzzum
On 11/5/00 1:15 pm Spuzzum wrote:
proc/fexist(path)
var/list/L = flist(path)
return (L.len>0)

Clever! I never thought of using a comparison operator to return a value. My code always looks like:

proc/fexist(path)
var/list/L = flist(path)
if(L.len > 0)
return 1
else
return 0


And you should be happy to know that your code meets the Deadron guidelines because it is more readable and clearly understandable than the shortcut.

Though it would be acceptable to cut it down to two lines:

if(L.len > 0) return 1
else return 0