home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / plbin.zip / pl / library / files.pl < prev    next >
Text File  |  1992-05-26  |  1KB  |  40 lines

  1. /*  files.pl,v 1.1.1.1 1992/05/26 11:51:36 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: file manipulation
  7. */
  8.  
  9. :- module(files,
  10.     [ can_open_file/2
  11.     ]).
  12.  
  13. %    can_open_file(+Path, +Mode)
  14. %    Succeeds if the user has access to `File' in mode `Mode'.  Fails
  15. %    silently if this is not the  case.   `Mode'  is  one  of  {read,
  16. %    write, both}.  This used to be difficult.  Since we have
  17. %    access_file/2 it is merely a Quintus compatibility predicate
  18. %    and should be in quintus.pl.  We will leave it here for compatibility
  19. %    reasons.
  20.  
  21. can_open_file(File, read) :- !,
  22.     access_file(File, read).
  23. can_open_file(File, write) :- !,
  24.     (   exists_file(File)
  25.     ->  access_file(File, write)
  26.         ;   path_dir_name(File, Dir),
  27.         access_file(Dir, write)
  28.     ).
  29. can_open_file(File, both) :-
  30.     access_file(File, read),
  31.     access_file(File, write).
  32.  
  33. path_dir_name(File, Dir) :-
  34.     '$file_base_name'(File, Base),
  35.     concat(RawDir, Base, File),
  36.     (   RawDir == ''
  37.     ->  Dir = '.'
  38.     ;   Dir = RawDir
  39.     ).
  40.