File name manipulation
Author(s): Daniel Cabeza, Angel Fernandez Pineda.
This library provides some small utilities to handle file name syntax.
Usage and interface
- Library usage:
:- use_module(library(filenames)). - Exports:
- Predicates:
no_path_file_name/2, file_directory_base_name/3, file_name_extension/3, basename/2, extension/2. - Regular Types:
atom_or_str/1.
- Predicates:
- Imports:
- System library modules:
assertions/native_props, lists. - Packages:
prelude, nonpure, assertions, nativeprops.
- System library modules:
Documentation on exports
The first argument must be instantiated to a string or atom. Whenever the first argument is an atom, the second argument will be an atom. Whenever the first argument is a string, the second argument will be a string.
This predicate will fail under any of the following conditions:
- First argument is not an atom, nor a string.
- Second argument is not the last given path item (given path is the first argument).
Those are the most usual usages of no_path_file_name/2:
?- no_path_file_name("/home/nexusV/somefile.txt",K). K = "somefile.txt" ? yes ?- no_path_file_name('/home/nexusV/somefile.txt',K). K = 'somefile.txt' ? yes ?-
Usage:no_path_file_name(Path,FileName)
FileName is the file corresponding to the given Path.
- Call and exit should be compatible with:
(filenames:atom_or_str/1)Path is an atom or a string
(filenames:atom_or_str/1)FileName is an atom or a string
Usage:file_directory_base_name(Path,Directory,BaseName)
Given a file path Path, Directory is the directory part and BaseName is the filename part. Directory does not end in '/' unless it is just '/'. Directory is '.' if Path does not contain '/'.
- Call and exit should be compatible with:
(filenames:atom_or_str/1)Path is an atom or a string
(filenames:atom_or_str/1)Directory is an atom or a string
(filenames:atom_or_str/1)BaseName is an atom or a string
- To create a file name from its components: name and extension. For instance:
?- file_name_extension(File,mywork,'.txt'). File = 'mywork.txt' ? yes ?-
- To split a file name into its name and extension. For Instance:
?- file_name_extension('mywork.txt',A,B). A = mywork, B = '.txt' ? yes ?-
Any other usage of file_name_extension/3 will cause the predicate to fail. Notice that valid arguments are accepted both as atoms or strings.
Usage:file_name_extension(FileName,BaseName,Extension)
Splits a FileName into its BaseName and Extension.
- Call and exit should be compatible with:
(filenames:atom_or_str/1)FileName is an atom or a string
(filenames:atom_or_str/1)BaseName is an atom or a string
(filenames:atom_or_str/1)Extension is an atom or a string
Test:file_name_extension(File,Name,Ext)
This is a bug, this test must succeeds.
- If the following properties do not hold at call time:
(term_basic:= /2)term_basic:File=/home/user/emacs.d/dummy
then the following properties do not hold upon exit:
(term_basic:= /2)term_basic:Name=/home/user/emacs.d/dummy
(term_basic:= /2)term_basic:Ext=
then the following properties do not hold globally:
(native_props:is_det/1)All calls of the form file_name_extension(File,Name,Ext) are deterministic.
(native_props:not_fails/1)All the calls of the form file_name_extension(File,Name,Ext) do not fail.
BaseName is FileName without extension. Equivalent to file_name_extension(FileName,BaseName,_). Useful to extract the base name of a file using functional syntax.
Usage:
- Call and exit should be compatible with:
(filenames:atom_or_str/1)FileName is an atom or a string
(filenames:atom_or_str/1)BaseName is an atom or a string
Extension is the extension (suffix) of FileName. Equivalent to file_name_extension(FileName,_,Extension). Useful to extract the extension of a file using functional syntax.
Usage:
- Call and exit should be compatible with:
(filenames:atom_or_str/1)FileName is an atom or a string
(filenames:atom_or_str/1)Extension is an atom or a string