Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!tektronix!ogcvax!omsvax!icalqa!hplabs!sri-unix!pereira From: pereira@sri-unix.UUCP Newsgroups: net.sources Subject: Prolog library: files.pl Message-ID: <96@sri-unix.UUCP> Date: Mon, 15-Aug-83 01:51:51 EDT Article-I.D.: sri-unix.96 Posted: Mon Aug 15 01:51:51 1983 Date-Received: Thu, 11-Aug-83 13:36:29 EDT Lines: 88 /* 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).