pereira@sri-unix.UUCP (08/15/83)
/* FILES.PL : Routines for playing with files UTILITY Lawrence Updated: 2 April 81 */ %%% Compile this module %%% FILES requires no other modules :- public check_exists/1, file_exists/1, open/1, open/2, close/2, delete/1. :- mode check_exists(+), file_exists(+), open(+), open(?,+), close(+,+), delete(+). % Check to see if a file exists and provide % an error message if it doesn't check_exists(File) :- file_exists(File), !. check_exists(File) :- ttynl, display('! File: '), display(File), display(' does not exist.'), ttynl, fail. % Succeed if a file exists, otherwise fail file_exists(File) :- atom(File), seeing(Old), ( nofileerrors ; fileerrors, fail ), see(File), fileerrors, seen, see(Old), !. % Open a file, checking that it exists open(File) :- check_exists(File), see(File). % Open a file and return current file open(Old,File) :- seeing(Old), open(File). % Close file and see old file again close(File,Old) :- close(File), see(Old). % Delete a file (note that rename requires that % the file be open) delete(File) :- open(Old,File), rename(File,[]), see(Old).