Add delete_directory/1 predicate to the files library

This commit is contained in:
Paulo Moura
2021-05-18 08:41:19 +01:00
parent e7d6811948
commit eeac3bc436
3 changed files with 25 additions and 0 deletions

View File

@@ -51,6 +51,7 @@
file_exists/1,
directory_exists/1,
delete_file/1,
delete_directory/1,
make_directory/1,
working_directory/2,
path_canonical/2,
@@ -95,11 +96,21 @@ delete_file(File) :-
list_of_chars(File),
'$delete_file'(File).
delete_directory(Directory) :-
directory_must_exist(Directory, delete_directory/1),
list_of_chars(Directory),
'$delete_directory'(Directory).
file_must_exist(File, Context) :-
( file_exists(File) -> true
; throw(error(existence_error(file, File), Context))
).
directory_must_exist(Directory, Context) :-
( directory_exists(Directory) -> true
; throw(error(existence_error(directory, Directory), Context))
).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dir0 is the current working directory, and the working directory
is changed to Dir.