%I'm trying to write a simple file existence handler, the samples
from the Quintus reference pages have not been quite what I needed.
In fact, I found some major problems with the example from the
Quintus reference pages (G.19-5 for my version -Errors and Exceptions)
Seems like it should be simple. I found an interesting result, however.
Here the general idea:
1) if you can 'see' the file, it must exist
2) else, it doesn't exist
This works great except that if you delete a file during the run and then check
for it's existence, it still says it exists! Ahi! Any ideas why? It appears
that Quintus loads the directory into memory once only.
%This is the code and a sample run of program in Quintus environment:
isfile(F,yes):-
see(F),
!.
isfile(_,no).
%------ load isfile.pl
| ?- [isfile].
% compiling file /tools/claire/claire8/addons/transactions/isfile.pl
% isfile.pl compiled in module user, 0.034 sec 340 bytes
yes
%--- try it with a known existing file
| ?- isfile('junk.stuff',X).
X = yes
%--- try it with a non-existent file
| ?- isfile(xxx,X).
! Existence error in argument 1 of see/1
! file '/tools/claire/claire8/addons/transactions/xxx' does not exist
! Unix error : No such file or directory
! goal: see(xxx)
%--- use built-in to turn off file errors.
| ?- nofileerrors.
yes
%--- try checking for non-existent file again
| ?- isfile(xxx,X).
X = no
%--- everything works so far!
%--- remove existing file
| ?- unix(system('rm junk.stuff')).
yes
%--- check to see file is gone
| ?- isfile('junk.stuff',X).
X = yes
%--- !!!!! what? why does this happen?
%note: checking for previously non-existing file give correct response
| ?- isfile(xxxx,X).
X = no