4.36 File System Interaction
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • File System Interaction
          • access_file/2
          • exists_file/1
          • file_directory_name/2
          • file_base_name/2
          • same_file/2
          • exists_directory/1
          • delete_file/1
          • rename_file/2
          • size_file/2
          • time_file/2
          • absolute_file_name/2
          • absolute_file_name/3
          • is_absolute_file_name/1
          • file_name_extension/3
          • directory_files/2
          • expand_file_name/2
          • prolog_to_os_filename/2
          • read_link/3
          • tmp_file/2
          • tmp_file_stream/3
          • make_directory/1
          • delete_directory/1
          • working_directory/2
          • chdir/1
    • Packages
Availability:built-in
file_directory_name(+File, -Directory)
Extracts the directory part of File. This predicate removes the longest match for the regular expression /*[^/]*/*$. If the result is empty it binds Directory to / if the first character of File is / and . otherwise. The behaviour is consistent with the POSIX dirname program.152Before SWI-Prolog 7.7.13 trailing / where not removed, translation /a/b/ into /a/b. Volker Wysk pointed at this incorrect behaviour.

See also directory_file_path/3 from library(filesex). The system ensures that for every valid Path using the Prolog (POSIX) directory separators, following is true on systems with a sound implementation of same_file/2.153On some systems, Path and Path2 refer to the same entry in the file system, but same_file/2 may fail. See also prolog_to_os_filename/2.

        ...,
        file_directory_name(Path, Dir),
        file_base_name(Path, File),
        directory_file_path(Dir, File, Path2),
        same_file(Path, Path2).