- append_directories(+Directories:list(atom), -Directory:atom) is det
- cat(+Out:ostream, +Files:list(atom)) is det
- change_file_name_extension(?FromFile:atom, ?ToExtension:atom, ?ToFile:atom) is det
- change_file_name_extension(?FromFile:atom, ?FromExtension:atom, ?ToExtension:atom, ?ToFile:atom) is det
- change_file_name_extensions(?FromFile:atom, ?ToExtensions:list(atom), ?ToFile:atom) is det
- change_file_name_extensions(?FromFile:atom, ?FromExtensions:list(atom), ?ToExtensions:list(atom), ?ToFile:atom) is det
- compress_file(+FromFile:atom) is det
- compress_file(+FromFile:atom, +ToFile:atom) is det
- compress_file(+FromFile:atom, -ToFile:atom) is det
- concatenate_files(+Files, +ConcatenatedFile) is det
- convert_file(+File:atom, +Format:atom) is det
- convert_file(+FromFile:atom, +Format:atom, ?ToFile:atom) is det
-
- See also
- - Formats are ‘documented’ over at
https://cgit.freedesktop.org/libreoffice/core/tree/filter/source/config/fragments/filters
- - Encodings are ‘documented’ over at
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
- create_directory(+Directory:atom) is det
- create_file_directory(+Path) is det
- Ensures that the directory structure for the given file exists.
- decompress_file(+FromFile:atom, +ToFile:atom) is det
- delete_files_by_extension(+Extension:atom) is det
- delete_files_by_extension(+Directory:atom, +Extension:atom) is det
- delete_files_by_extensions(+Extensions:list(atom)) is det
- delete_files_by_extensions(+Directory:atom, +Extensions:list(atom)) is det
- directory_file_path2(+Directory:atom, +File:atom, -Path:atom) is det
- directory_file_path2(+Directory:atom, -File:atom, -Path:atom) is nondet
- directory_file_path2(-Directory:atom, -File:atom, +Path:atom) is det
- Instantiation pattern (+,-,-) is not supported by
directory_file_path/3 from the standard library.
- directory_parent(+ChildDirectory:atom, -ParentDirectory:atom) is det
- directory_path(+Directory:atom, -Path:atom) is nondet
- directory_path(-Directory:atom, +Path:atom) is det
- directory_path_recursive(+Directory:atom, -Path:atom) is nondet
- directory_subdirectories(+Directory:atom, -Subdirectories:list(atom)) is det
- directory_subdirectories(-Directory:atom, +Subdirectories:list(atom)) is det
- Occurrences of `.
and
.. in
Directory' are resolved.
The empty atom in the first position indicates the root directory.
For absolute directory names the first subdirectory name is the
empty atom.
- directory_subdirectory(+Directory:atom, +SubDirectory:atom) is semidet
- directory_subdirectory(+Directory:atom, -SubDirectory:atom) is nondet
- directory_subdirectory(+Directory:atom, +Local:atom, +SubDirectory:atom) is semidet
- directory_subdirectory(+Directory:atom, +Local:atom, -SubDirectory:atom) is semidet
- directory_subdirectory(+Directory:atom, -Local:atom, -SubDirectory:atom) is nondet
- file_call(+File:atom, :Goal_1) is det
- file_extension(+File:atom, -Extension:atom) is nondet
- file_extensions(+File:atom, -Extensions:list(atom)) is det
- file_extensions_media_type(+Extensions:list(atom), -MediaType:media_type) is det
- file_is_fresh(+File:atom, +LastModified:nonneg) is det
- file_line(+File:atom, -Line:string) is nondet
- file_media_type(+File:atom, -MediaType:media_type) is nondet
- file_mode(+File:atom, +Mode:oneof([append,read,write])) is det
-
- throws
- - existence_error
- - permission_error
- file_name(+File:atom, +Name:atom) is semidet
- file_name(+File:atom, -Name:atom) is det
- file_name_extension2(+File:atom, -Name:atom, -Extension:atom) is det
- file_name_extension2(-File:atom, +Name:atom, +Extension:atom) is det
- file_name_extensions(+File:atom, -Name:atom, -Extensions:list(atom)) is det
- file_name_extensions(-File:atom, +Name:atom, +Extensions:list(atom)) is det
- file_size(+File:atom, -Size:nonneg) is det
-
- See also
- - Wrapper around size_file/2.
- file_to_string(+File:atom, -String:string) is det
- guess_file_encoding(+File:atom, +Encoding:atom) is det
- guess_file_encoding(+File:atom, -Encoding:atom) is det
- When Encoding is instantiated to an encoding different from the
guessed encoding, the error unexpected_encoding/2 is thrown.
- See also
- - guess_encoding/2.
- home_directory(+Directory:atom) is semidet
- home_directory(-Directory:atom) is nondet
- is_dummy_file(+File:atom) is semidet
- is_empty_directory(+Directory:atom) is semidet
- is_empty_file(+File:atom) is semidet
- peek_file(+File:atom, +Size:nonneg, -String:string) is det
- read_from_file(+File:atom, :Goal_1) is det
- read_from_file(+File:atom, :Goal_1, +Options:options) is det
- Calls Goal_1 on the input stream derived from the given File. If
the filen name ends in `.gz', GNU zip decompression is applied.
- read_write_file(+File:atom, :Goal_2) is det
- read_write_file(+File:atom, :Goal_2, +ReadOptions:options, +WriteOptions:options) is det
- read_write_files(+FromFile:atom, +ToFile:atom, :Goal_2) is det
- read_write_files(+FromFile:atom, +ToFile:atom, :Goal_2, +Options:options) is det
- read_write_files(+FromFile:atom, +ToFile:atom, :Goal_2, +ReadOptions:options, +WriteOptions:options) is det
- recode_file(+FromFile:atom) is det
- recode_file(+FromFile:atom, +FromEncoding:atom) is det
- Recodes the given File from the given FromEncoding to UTF-8.
- recode_files(+FromFile:atom, +ToFile:atom) is det
- recode_files(+FromFile:atom, +FromEncoding:atom, +ToFile:atom) is det
- sort_file(+File:atom) is det
- sort_file(+File:atom, +Options:options) is det
- touch(+File) is det
- working_directory(-Directory:atom) is det
- write_to_file(+File:atom, :Goal_1) is det
- write_to_file(+File:atom, :Goal_1, +Options:options) is det
- If File's directory does not exist it is created.
Re-exported predicates
The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
- set_time_file(+File, -OldTimes, +NewTimes) is det
- Query and set POSIX time attributes of a file. Both OldTimes and
NewTimes are lists of option-terms. Times are represented in
SWI-Prolog's standard floating point numbers. New times may be
specified as
now
to indicate the current time. Defined options
are:
- access(Time)
- Describes the time of last access of the file. This value
can be read and written.
- modified(Time)
- Describes the time the contents of the file was last
modified. This value can be read and written.
- changed(Time)
- Describes the time the file-structure itself was changed by
adding (
link()
) or removing (unlink()
) names.
Below are some example queries. The first retrieves the
access-time, while the second sets the last-modified time to the
current time.
?- set_time_file(foo, [access(Access)], []).
?- set_time_file(foo, [], [modified(now)]).
- link_file(+OldPath, +NewPath, +Type) is det
- Create a link in the filesystem from NewPath to OldPath. Type
defines the type of link and is one of
hard
or symbolic
.
With some limitations, these functions also work on Windows. First
of all, the underlying filesystem must support links. This requires
NTFS. Second, symbolic links are only supported in Vista and later.
- Errors
- -
domain_error(link_type, Type)
if the requested link-type
is unknown or not supported on the target OS.
- relative_file_name(+Path:atom, +RelToFile:atom, -RelPath:atom) is det
- relative_file_name(-Path:atom, +RelToFile:atom, +RelPath:atom) is det
- True when RelPath is Path, relative to the file RelToFile. Path and
RelTo are first handed to absolute_file_name/2, which makes the
absolute and canonical. Below are two examples:
?- relative_file_name('/home/janw/nice',
'/home/janw/deep/dir/file', Path).
Path = '../../nice'.
?- relative_file_name(Path, '/home/janw/deep/dir/file', '../../nice').
Path = '/home/janw/nice'.
Add a terminating /
to get a path relative to a directory, e.g.
?- relative_file_name('/home/janw/deep/dir/file', './', Path).
Path = 'deep/dir/file'.
- Arguments:
-
All | - paths must be in canonical POSIX notation, i.e.,
using / to separate segments in the path. See
prolog_to_os_filename/2. |
- bug
- - It would probably have been cleaner to use a directory
as second argument. We can not do such dynamically as this
predicate is defined as a syntactical operation, which
implies it may be used for non-existing paths and URLs.
- directory_file_path(+Directory, +File, -Path) is det
- directory_file_path(?Directory, ?File, +Path) is det
- True when Path is the full path-name for File in Dir. This is
comparable to
atom_concat(Directory, File, Path)
, but it ensures
there is exactly one / between the two parts. Notes:
- directory_member(+Directory, -Member, +Options) is nondet
- True when Member is a path inside Directory. Options defined are:
- recursive(+Boolean)
- If
true
(default false
), recurse into subdirectories
- follow_links(+Boolean)
- If
true
(default), follow symbolic links.
- file_type(+Type)
- See absolute_file_name/3.
- extensions(+List)
- Only return entries whose extension appears in List.
- file_errors(+Errors)
- How to handle errors. One of
fail
, warning
or error
.
Default is warning
. Errors notably happen if a directory is
unreadable or a link points nowhere.
- access(+Access)
- Only return entries with Access
- matches(+GlobPattern)
- Only return files that match GlobPattern.
- exclude(+GlobPattern)
- Exclude files matching GlobPattern.
- exclude_directory(+GlobPattern)
- Do not recurse into directories matching GlobPattern.
- hidden(+Boolean)
- If
true
(default), also return hidden files.
This predicate is safe against cycles introduced by symbolic links
to directories.
The idea for a non-deterministic file search predicate comes from
Nicos Angelopoulos.
- copy_file(+From, +To) is det
- Copy a file into a new file or directory. The data is copied as
binary data.
- make_directory_path(+Dir) is det
- Create Dir and all required components (like mkdir -p). Can
raise various file-specific exceptions.
- ensure_directory(+Dir) is det
- Ensure the directory Dir exists. Similar to make_directory_path/1,
but creates at most one new directory, i.e., the directory or its
direct parent must exist.
- copy_directory(+From, +To) is det
- Copy the contents of the directory From to To (recursively). If
To is the name of an existing directory, the contents of From
are copied into To. I.e., no subdirectory using the basename of
From is created.
- delete_directory_and_contents(+Dir) is det
- Recursively remove the directory Dir and its contents. If Dir is
a symbolic link or symbolic links inside Dir are encountered,
the links are removed rather than their content. Use with care!
- delete_directory_contents(+Dir) is det
- Remove all content from directory Dir, without removing Dir
itself. Similar to delete_directory_and_contents/2, if symbolic
links are encountered in Dir, the links are removed rather than
their content.
- chmod(+File, +Spec) is det
- Set the mode of the target file. Spec is one of
+Mode
, -Mode
or
a plain Mode, which adds new permissions, revokes permissions or
sets the exact permissions. Mode itself is an integer, a POSIX
mode name or a list of POSIX mode names. Defines names are suid
,
sgid
, svtx
and all names defined by the regular expression
[ugo]*[rwx]*
. Specifying none of "ugo" is the same as specifying
all of them. For example, to make a file executable for the owner
(user) and group, we can use:
?- chmod(myfile, +ugx).
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.
- compress_file(Arg1, Arg2)
- convert_file(Arg1, Arg2, Arg3)
- delete_files_by_extension(Arg1, Arg2)
- delete_files_by_extensions(Arg1, Arg2)
- directory_file(Arg1, Arg2)
- read_from_file(Arg1, Arg2, Arg3)
- read_write_file(Arg1, Arg2, Arg3)
- read_write_file(Arg1, Arg2, Arg3, Arg4)
- read_write_files(Arg1, Arg2, Arg3, Arg4)
- read_write_files(Arg1, Arg2, Arg3, Arg4, Arg5)
- recode_file(Arg1, Arg2)
- recode_files(Arg1, Arg2, Arg3)
- sort_file(Arg1, Arg2)
- write_to_file(Arg1, Arg2, Arg3)
- copy_stream_type(Arg1, Arg2)
- guess_encoding(Arg1, Arg2)
- number_of_open_files(Arg1)
- read_line_to_atom(Arg1, Arg2)
- read_line_to_number(Arg1, Arg2)
- read_stream_to_atom(Arg1, Arg2)
- read_stream_to_string(Arg1, Arg2)
- recode_stream(Arg1, Arg2, Arg3)
- stream_line(Arg1, Arg2)
- stream_line_column(Arg1, Arg2, Arg3)
- stream_metadata(Arg1, Arg2)
- wc(Arg1, Arg2)