
-----------------------------------
Bege
Wed Apr 23, 2003 5:06 pm

Reading a file: checking to see if a file exists.
-----------------------------------
Does anyone know what the code is to check if a file exists?

Ex: If the user was asked to enter the name of a file to load, then the program could check if the file exists. Then the program wouldn't crash when the user enters a file name which does not exist, but rather just tell the user that that file does not exist.

-----------------------------------
Mazer
Wed Apr 23, 2003 5:11 pm


-----------------------------------
File.Exists (pathName : string) : boolean

it's a function that takes a path name for a file and returns true or false depending on whether or not the file exists.

eg

var filename : string

get filename

if File.Exists (filename) then
    put "So, there you go."
end if


well, that should do it.

-----------------------------------
Tony
Wed Apr 23, 2003 5:12 pm


-----------------------------------
well you could use assert, but I think that will terminate the program.

when you open the file, the pointer to it is assigned a possitive integer. If that variable is 0 or a negative, it means file was not opened so you should display an appropriate message.


var file:int

open : file, "test.txt", get

if file 