Tests if a file or directory exists.
Returns true if $path points to an existing file or directory,
false otherwise.
The root directory of a UNIX-based system and the volume roots of a Windows system are considered directories.
false is returned if the existence of the path cannot be determined,
for example because of insufficient access rights.
Tests if $path points to a directory.
Returns true if $path points to an existing directory
as defined in false.
The root directory of a UNIX-based system and the volume roots of a Windows system are considered directories.
Tests if $path points to a regular file.
Returns true if $path points to an existing regular file
as defined in false.
Tests if $path is absolute.
Returns true if $path is absolute,
false otherwise.
A path is absolute if it contains all the components necessary to identify a file location, without reference to a current drive or a current working directory.
This function is
All UNC file names are absolute.
The function may return a different result for the same path on a Windows and a UNIX-based system.
true on a UNIX-based system and
false on a Windows system.New in 4.0.
Returns the last modification time of a file or directory.
Returns an xs:dateTime item representing the last modification of
a file or directory.
Returns the size of a file or directory.
If $path points to a file, returns the byte size of this file.
Otherwise, if it points to a directory, returns either 0 or,
if $recursive is true, the sum of the byte sizes of all files
that are contained in this directory and its subdirectories. The sizes of the
directories themselves are not included.
$recursive parameter added.
Appends a serialized value to a file.
Serializes a value and appends the resulting string to a file.
If the file pointed to by $file does not exist,
a new file will be created.
The $options argument controls the way how $value is serialized.
The semantics are the same as for fn:serialize, the encoding stage will not be skipped by
this function.
The function returns the empty sequence if the operation is successful.
fragments.xml. The file is created if it does not already exist.snippets.json.$options can now be a map, in alignment with fn:serialize.
Appends binary data to a file.
Appends the binary data of an xs:base64Binary item to a file.
If the file pointed to by $file does not exist, a new file will be
created.
The function returns the empty sequence if the operation is successful.
0x41, 0x42 and 0x43
to the file data.bin.
The file is created if it does not already exist.Appends a string to a file.
Appends a string to a file.
If the file pointed to by $file does not exist, a new file will be
created.
The string is encoded with the encoding specified by $encoding.
Encoding names are matched case-insensitively. It is
The function returns the empty sequence if the operation is successful.
todos.txt.
The file is created if it does not already exist.Appends a sequence of strings to a file, each followed by the operating-system specific newline character.
Appends a sequence of strings to a file, each followed by the operating-system specific
newline character.
If the file pointed to by $file does not exist, a new file will be created.
The strings are encoded with the encoding specified by $encoding.
Encoding names are matched case-insensitively. It is
The function returns the empty sequence if the operation is successful.
numbers.txt. The file is created if it does not already exist.Copies a file or a directory.
Copies a file or a directory given a source and a target path.
The following rules apply if $source points to a file:
if $target does not exist, it will be created.
if $target is a file, it will be overwritten.
if $target is a directory, the file will be created in that
directory with the name of the source file. If a file already exists, it
will be overwritten.
Otherwise, if $source points to a directory:
if $target does not exist, it will be created as directory, and
the contents of the source directory, including all subdirectories, are copied
recursively to this directory with their existing local names.
if $target is a directory, the source directory with all its
files will be copied into the target directory. At each level, if a file
already exists in the target with the same name as in the source, it is
overwritten. If a directory already exists in the target with the same name
as in the source, it is not removed, it is recursed in place.
If it does not exist, it is created before recursing.
If $source and $target point to the same file or directory,
the function has no effect.
If $source points to a directory and $target is located
inside $source (that is, $target is a descendant path of
$source), the error
Other cases will result in one of the errors listed below.
It is
The function returns the empty sequence if the operation is successful. No rollback to the original state will be possible if an error occurs during the operation.
The function should be used with caution: it may create arbitrary subdirectories, it will silently overwrite existing files, and it provides no rollback mechanism in the event of an error occurring partway through.
a.txt in the
same directory, named b.txt.a.txt with the same name
in the parent directory.dir
in the dir2. If
dir2 already exists, the contents of dir will be copied
into that directory. The trailing directory slashes are optional.Error case added when target is inside source directory.
Creates a directory.
Creates a directory unless it already exists. The operation will also create non-existing parent directories.
The function returns the empty sequence if the operation is successful.
examples in the
Creates a temporary directory.
Creates a temporary directory with an optional $prefix and
$suffix in the filename, and returns the full path to the created directory.
The path will point to a directory that did not exist before the function was called.
The name of the created directory begins with $prefix and ends with
$suffix; the remainder of the name is
$prefix or $suffix is omitted or an empty sequence, it is
$dir supplies the path of the directory in which the temporary directory
is created. If it is omitted or an empty sequence, the directory will be created
inside the operating-system specific default temporary-file directory.
The created directory will not be deleted automatically after query execution.
All parameters are optional now.
Creates a temporary file.
Creates an empty temporary file with an optional $prefix and
$suffix in the filename, and returns the full path to the created file.
The path will point to a file that did not exist before the function was called.
The name of the created file begins with $prefix and ends with
$suffix; the remainder of the name is
$prefix or $suffix is omitted or an empty sequence, it is
.tmp).
$dir supplies the path of the directory in which the temporary file is
created. If it is omitted or an empty sequence, the file will be created inside
the operating-system specific default temporary-file directory.
The created file will not be deleted automatically after query execution.
.txt in the
temporary-file directory.All parameters are optional now.
Deletes a file or a directory.
Deletes a file or a directory from the file system if it exists:
If $path points to a file or empty directory, it is deleted.
Otherwise, if $path points to a non-empty directory:
if $recursive is false, an error is raised.
Otherwise, the directory and all its contents are deleted recursively.
Otherwise, nothing happens.
The function returns the empty sequence if the operation is successful.
No rollback to the original state will be possible if an error occurs during the operation.
list.txt from the
example and
all its contents, including files and directories, recursively.Non-existing paths are now ignored.
Lists all files and directories in a given directory.
Lists all files and directories in a given directory.
In contrast to $dir.
The order of the items in the resulting sequence is not defined.
The references to the specified directory and its parent directory
(. and ..) are not returned.
Each returned string is the path of the entry relative to $dir,
with path segments separated by the implementation-defined directory separator;
paths that refer to directories carry a trailing separator. For example,
file:list('/tmp', true()) may return paths such as
foo.txt, sub/, and sub/inner.txt.
If $recursive is true, all directories and files will be returned
that are found while recursively traversing the given directory.
Otherwise, only the contents of the specified directory will be returned.
The $pattern argument is used to define a name pattern in the glob syntax.
If supplied, only the paths of the files and directories whose names are matching the pattern
will be returned.
An implementation
* for matching any number of unknown characters and
? for matching one unknown character.
The pattern is matched against the name of a file or directory, i.e., against the last segment of a returned path, and not against the full relative path. The recursive traversal of subdirectories is not affected by the pattern: the contents of a directory are returned even if the name of the directory does not match the pattern.
It is
A related function is
$pattern can now be supplied without supplying $recursive.
Lists all root directories of the file system.
Lists all root directories of the file system:
On a Windows system, root directories are usually the letters of the
currently available drives, followed by a colon and a backslash
(for example, C:\ and D:\).
On a UNIX-based system, it is usually a single slash, denoting the root directory.
Dynamically available UNC file names are not returned by this function.
New in 4.0.
Moves a file or a directory.
Moves a file or a directory given a source and a target path.
The following rules apply if $source points to a file:
if $target does not exist, it will be created.
if $target is a file, it will be overwritten.
if $target is a directory, the file will be created in that
directory with the name of the source file. If a file already exists, it
will be overwritten.
Otherwise, if $source points to a directory:
if $target does not exist, it will be created as directory, and
the contents of the source directory, including all subdirectories, are moved
to this directory with their existing local names.
if $target is a directory, the source directory with all its
files will be moved into the target directory. If the target directory
contains a directory with the same name as the source,
the error
If $source and $target point to the same file or directory,
the function has no effect.
If $source points to a directory and $target is located
inside $source (that is, $target is a descendant path of
$source), the error
Other cases will result in one of the errors listed below.
After a successful move, $source no longer exists.
It is
The function returns the empty sequence if the operation is successful. No rollback to the original state will be possible if an error occurs during the operation.
The function should be used with caution: it may create arbitrary subdirectories, it will silently overwrite existing files, and it provides no rollback mechanism in the event of an error occurring partway through.
a.txt to b.txt.a.txt to the parent directory.dir to dir2. If dir2
already exists, moves the source directory into that directory.
The trailing directory slashes are optional.Error case added when target is inside source directory.
Returns the binary content of a file.
Returns the content of a file as an xs:base64Binary item.
Chunks of a file can be read by supplying $offset (0-based) and $length.
If no value is supplied for $length, all remaining bytes will be read.
true if the file data.bin
contains the single byte 0x41.data.bin.$length can now be supplied without supplying $offset.
Returns the content of a file as a string.
Returns the content of a file in its string representation.
Newlines are normalized: Any
The $options argument, for backwards compatibility reasons, may be supplied
either as a map, or as a string. Supplying a value $S that is not a map
is equivalent to supplying the map { "encoding": $S }.
After that substitution, the
The entries that may appear in the $options map are as follows:
fallback option is true, any character that
cannot be decoded or that is not a The effective encoding and the effective start position are determined by invoking
encoding option. The content of the file is
decoded with the effective encoding, starting at the effective start position.
As a consequence of these rules, encoding names are matched case-insensitively, and a byte order mark at the start of the file is not included in the result.
true if the file todos.txt
contains the specified string.$options parameter added.
The normalization of newlines has been made explicit.
A fallback option is now provided to address characters that cannot be decoded or are not permitted.
Returns the contents of a file as a sequence of strings, separated at newline boundaries.
Returns the contents of a file as a sequence of strings, separated at newline boundaries.
Any of the character sequences
The $options argument, for backwards compatibility reasons, may be supplied
either as a map, or as a string. Supplying a value $S that is not a map
is equivalent to supplying the map { "encoding": $S }.
After that substitution, the
The entries that may appear in the $options map are as follows:
fallback option is true, any character that
cannot be decoded or that is not a The effective encoding and the effective start position are determined by invoking
encoding option. The content of the file is
decoded with the effective encoding, starting at the effective start position.
As a consequence of these rules, encoding names are matched case-insensitively, and a byte order mark at the start of the file is not included in the result.
$fallback parameter added.
The $fallback parameter has been integrated into the options map.
Writes a serialized value to a file.
Serializes a value and writes the resulting string to a file.
If the file pointed to by $file already exists, it will be overwritten;
otherwise, it will be created.
The $options argument controls the way how $value is serialized.
The semantics are the same as for fn:serialize, the encoding stage will not be skipped by
this function.
The function returns the empty sequence if the operation is successful.
numbers.txt.US-ASCII and
writes it to the file result.xml.$options can now be a map, in alignment with fn:serialize.
Writes binary data to a file.
Writes the binary data of an xs:base64Binary item to a file.
If the file pointed to by $file already exists, it will be overwritten;
otherwise, it will be created.
If $offset (0-based) is specified, data will be written
starting at this file position, and existing bytes will be overwritten.
The operation may resize the existing file.
A file that does not exist is treated as an empty file; only an offset of
0 is permitted in this case.
The function returns the empty sequence if the operation is successful.
Supplying an offset makes sense only if the file already exists.
0x41, 0x42 and 0x43
to the file data.bin.0x44.Writes a string to a file.
Writes a string to a file.
If the file pointed to by $file already exists, it will be overwritten;
otherwise, it will be created.
The string is encoded with the encoding specified by $encoding.
Encoding names are matched case-insensitively. It is
The function returns the empty sequence if the operation is successful.
todos.txt.
The file is created if it does not already exist.Writes strings to a file.
Writes strings to a file, each followed by the operating-system specific newline character.
If the file pointed to by $file already exists, it will be overwritten;
otherwise, it will be created.
The strings are encoded with the encoding specified by $encoding.
Encoding names are matched case-insensitively. It is
The function returns the empty sequence if the operation is successful.
numbers.txt.Returns the name of a file or directory.
Returns the name of a file or directory, i.e., the last segment of the supplied path. A trailing directory separator is ignored. If the path is a file URI, the name is derived from its path component.
An empty string is returned if the path points to a root directory or is empty.
This function is
Returns the path to the parent directory of a given path.
Transforms the given path into an absolute path, as specified by
An empty sequence is returned if the path points to a root directory.
The inverse function is
Returns the paths of all files and directories that are located in the given directory.
Returns the paths of all files and directories that are located in the given
directory. The order of the items in the resulting sequence is not defined.
The references to the specified directory and its parent directory
(. and ..) are not returned.
Each returned string is composed of the supplied path and the name of the file or
directory, separated by the directory separator as described in
file:children('/tmp') may return paths such as
/tmp/foo.txt (a file) and /tmp/sub/ (a directory).
The inverse function is
Returns the paths of all files and directories that are located in the given directory and its subdirectories.
Returns the paths of all files and directories that are located in the given
directory and its subdirectories. The order of the items in the resulting sequence
is not defined.
The references to the specified directory and its parent directory
(. and ..) are not returned.
Each returned string is composed of the supplied path and the relative path from that
directory to the entry, separated by the directory separator as described in
file:descendants('/tmp') may return paths
such as /tmp/foo.txt, /tmp/sub/, and
/tmp/sub/inner.txt.
The entries that may appear in the $options map are as follows (the
$path, which is
always traversed. The traversal descends
into a directory only if the predicate returns true.
In all cases, a directory is subject to the filter option.
The $path argument is the path of the directory, in the format
described above.
true. The predicate does not influence the traversal:
a directory for which it returns false is omitted from the result, but
its descendants are still visited, and may be added to the result. Use the
recurse option to skip a subtree. The $path argument is the
path of the entry, in the format described above.0
restricts the result to the entries of the specified directory. A negative value is
treated as 0. The empty sequence imposes no limit.If the recurse or filter predicate returns an empty sequence,
it is treated as false.
The most effective way to speed up the traversal of large directory structures is to skip the recursion of subdirectories.
node_modules directories.New in 4.0.
$options parameter added.
Transforms a path to a canonical representation.
Transforms a URI, an absolute path, or relative path to a canonical, operating-system specific path representation. A canonical path is both absolute and unique and thus contains no redirections such as references to parent directories or symbolic links.
If the resulting path points to a directory, it will be suffixed with the operating-system specific directory separator.
/ on a UNIX-based system.
On a Windows system, the result depends on the current root directory.Transforms a file system path into a URI.
Transforms a file system path into a URI with the file scheme. If the
path is relative, it is first resolved against the
The path is neither checked for correctness nor looked up in the file system.
file:///temp on a UNIX-based system.
On a Windows system, the result depends on the current root directory.%20.Transforms a relative path into an absolute operating system path.
Transforms a relative path into an absolute operating system path. The following rules apply in order:
If $path is an absolute path, it is not changed.
Otherwise, if $base is the empty sequence, $path is
resolved against the
Otherwise, it is resolved against the supplied base path or, if the base path does not point to a directory, to its parent directory. An error is raised if the base is a relative path.
If the resulting path points to a directory, it will be suffixed with the operating-system specific directory separator.
C:/Temp has no trailing separator, it is treated as a file path.
C:/Temp/ is treated as a directory.
$base parameter added.
Returns the directory separator.
Returns the value of the operating-system specific directory separator, which usually
is / on UNIX-based systems and \ on Windows systems.
Returns the line separator.
Returns the value of the operating-system specific line separator, which usually is
on UNIX-based systems, on
Windows systems and on old Mac systems.
Returns the path separator.
Returns the value of the operating-system specific path separator, which usually is
: on UNIX-based systems and ; on Windows systems.
Returns the path to the temporary-file directory.
Returns the path to the default temporary-file directory of an operating system.
Returns the base directory.
Returns the file:parent(static-base-uri()). Otherwise, it returns an empty sequence
todos.txt to the Returns the current working directory.
Returns the