1:- module(bc_files, [
    2    directory_only_files/2, % +Directory, -Files
    3    remove_directory/1      % +Directory
    4]).    5
    6% Finds directory entries that
    7% are files.
    8
    9directory_only_files(Directory, Files):-
   10    directory_files(Directory, Entries),
   11    exclude(not_file(Directory), Entries, Files), !.
   12
   13not_file(_, '.').
   14not_file(_, '..').
   15not_file(Base, Directory):-
   16    atomic_list_concat([Base, '/', Directory], Path),
   17    exists_directory(Path).
   18
   19% Removes the given directory
   20% recursively.
   21
   22remove_directory(Directory):-
   23    directory_files(Directory, Entries),
   24    exclude(ignored_file, Entries, Files),
   25    maplist(join_directory(Directory), Files, Joined),
   26    maplist(remove_directory_entry, Joined),
   27    delete_directory(Directory).
   28
   29ignored_file('.').
   30ignored_file('..').
   31
   32join_directory(Directory, Entry, Joined):-
   33    atomic_list_concat([Directory, '/', Entry], Joined).
   34
   35remove_directory_entry(Entry):-
   36    (   exists_directory(Entry)
   37    ->  remove_directory(Entry)
   38    ;   delete_file(Entry))