Re:File existance test
How to find out if a file exists, given its filename.
How Borland Pascal <5.0-or-so did it:
Assign(InFile,FileName);
{$I-} {switch off I/O error halting; all future I/O errors simply set the
function result of the builtin "function IOResult: Integer" to a
non-zero value, and don't crash.}
Reset(InFile); {this _would_ crash, if not for the $I-, if the file didn't
exist; instead, it sets IOResult}
{$I+} {switch checking back on}
if IOResult <> 0 then
WriteLn('File does not exist!')
else
begin
Close(InFile); {don't forget this bit!}
WriteLn('File exists!');
end;
How Borland 5.0+ does it:
if FileSearch(FileName,'') = '' then {can't find matching name in directory}
WriteLn('File does not exist!')
else
WriteLn('File exists!');
How you can do it if you have a function like "FindFirst":
FindFirst(FileName, {other parameters});
if {whatever the result of that find was is erroneous, or the found name is
blank} then
WriteLn('File does not exist!')
else
WriteLn('File exists!');
If you have FindFirst (a routine to find a file matching a filemask (eg
*.TXT) in the current directory, returning the name) or a similar directory
scanning routing, that'd be the way to go. Alternatively, if your version
of Reset doesn't crash, test EoF immediately -- tho that would also be true
if the file exists but is empty.
Good luck! I'd love to hear what you come up with!
: Eric :
--
Let's just say that if complete and utter chaos was light- | Paul Sleigh
ning, he'd be the sort to stand on a hilltop in a thunder- | Eric the Fruitbat
storm wearing wet copper armour and shouting 'All gods are | fruitbat@canberra
bastards'. [T Pratchett: Rincewind discussing Twoflower] | .DIALix.oz.au