Checking File Existence in Quintus PROLOG 
Author Message
 Checking File Existence in Quintus PROLOG

Sorry about the duplicate mail. Forgot to put Subject in first send.

%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



Mon, 25 May 1998 03:00:00 GMT  
 Checking File Existence in Quintus PROLOG
%Found my own answer.  Need a 'seen'.

isfile(F,yes):-
   see(F),
   !,
   seen.%<-------------
isfile(_,no).

%This works well and you don't have to use exception handling.  
%you do need to use
         prolog_flag(fileerrors,Old,off)...
         isfile(F,YESNO),
          .... more processing
         prolog_flag(fileerrors,_,Old)
to make sure file error checking status is maintained.



Tue, 26 May 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. X interface in Quintus prolog or C(C++) interface in Quintus prolog

2. Unification with Occur-Check in Quintus-Prolog

3. Checking for file existence in labview 6.1

4. Checking for the existence of a file.

5. Checking File Existence in Regina ReXX Win95

6. check for file/directory existence

7. How to Check File Existence?

8. need to intercept existence error for facts in Quintus

9. Quintus Prolog++ & AAIS Prolog

10. Help on ProLog by BIM versus Quintus Prolog

11. How to check a given class for existence?

12. Checking for existence of directories

 

 
Powered by phpBB® Forum Software