Please check the errata for any errors or issues reported since publication.
See also translations.
This document is also available in these non-normative formats: Specification in XML format and XML function catalog.
Copyright © 2000 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This document defines a file system API for XPath 4.0. It defines extension functions to perform file system related operations such as listing, reading, or writing files or directories.
The document is an update of the original [EXPath File 1.0] specification, developed by the EXPath Community Group, defined for [XML Path Language (XPath) 2.0] and published in 2013.
The principal semantic alteration is use of functional argument defaults available in XPath 4.0.
These functions are defined for use in [XML Path Language (XPath) 4.0] and [XQuery 4.1: An XML Query Language] and [XSL Transformations (XSLT) Version 4.0] and other related XML standards. The signatures and summaries of functions defined in this document are available at: https://qt4cg.org/specifications/EXPath/file-40/.
A summary of changes since published version 1.0 (the XPath 2.0 version) is provided at F Changes since version 1.0.
This version of the specification is work in progress. It is produced by the QT4 Working Group, officially the W3C XSLT 4.0 Extensions Community Group. Individual functions specified in the document may be at different stages of review, reflected in their History notes. Comments are invited, in the form of GitHub issues at https://github.com/qt4cg/qtspecs.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
Changes in 4.0 ⬇
Use the arrows to browse significant changes since the 1.0 version of this specification.
Sections with significant changes are marked Δ in the table of contents. New functions introduced in this version are marked ➕ in the table of contents.
The purpose of this document is to define functions to manipulate files within a local filesystem and their representations, for inclusion in XPath 4.0, XQuery 4.0, and XSLT 4.0.
The exact syntax used to call these functions and operators is specified in [XML Path Language (XPath) 4.0], [XQuery 4.1: An XML Query Language] and [XSL Transformations (XSLT) Version 4.0].
This document defines several classes of functions:
Functions to examine the properties of files, such as size and modification dates.
Functions to perform basic operations on files as entities, such as copying, deletion, creating directories and establishment of temporary files.
Functions to read and write to and from files in various formats.
Functions to access and manipulate file paths.
Functions to examine properties of the underlying file system and current context, such as establishing the current working directory or the characters used for various separators within paths or files.
References to specific sections of other specifications are indicated by cross-document links in this document. Each such link consists of a pointer to a specific section followed a superscript specifying the linked document. The superscripts have the following meanings: FO40 [XQuery and XPath Functions and Operators 4.0], SER30 [XSLT and XQuery Serialization 3.0] and XS2 [XML Schema Part 2: Datatypes Second Edition] .
Error conditions are identified by a code (a QName
.) When such an
error condition is reached in the evaluation of an expression, a dynamic error
is thrown, with the corresponding error code (as if the standard XPath function
error()
had been called.)
In this specification these codes use the http://expath.org/ns/file
namespace and a “descriptive string” local part, e.g. [file:not-found], rather than the
http://www.w3.org/2005/xqt-errors
namespace and alpha-numeric local
part, e.g. err:FOCH0004
, used in [XQuery and XPath Functions and Operators 4.0]. These error codes were chosen originally in the 1.0 version of 2013.
All file paths are specified as strings, and are resolved against the current working directory. The current working directory is implementation-defined: For example, it can be the file system directory from which a query processor was started.
An implementation must accept absolute and relative UNIX/Linux and Windows paths as well as absolute file URIs. Some examples:
C:\Test Dir\my file.xml
: An absolute path on Windows
platforms.
/Test Dir/my file.xml
: An absolute path on UNIX-based
platforms.
C:\\\Test Dir//\\my file.xml
: An absolute path on Windows
platforms that tolerates an arbitrary number of slashes and
backslashes.
my file.xml
: A relative path, pointing to a file in the
current working directory.
file:///C:/Test%20Dir/my%20file.xml
: An absolute file URI on
Windows platforms.
file:///Test%20Dir/my%20file.xml
: An absolute path on
UNIX-based platforms.
Before further processing, all paths are normalized to an implementation-dependentFO representation (which usually is the representation of the underlying operating system).
It is implementation-dependentFO as to whether the error [file:invalid-path] is raised if a path is invalid.
Whenever a function returns a string that refers to a directory, it is suffixed with the system-specific directory separator.
The function file:base-dir
can be used to resolve file operations
against the directory of the base URI:
let $filename := "input.txt" let $path := file:resolve-path($filename, file:base-dir()) return file:read-text($path)
Most functions are marked as nondeterministicFO, which means they are not guaranteed to perform the same operations and produce identical results when being called repeatedly. A processor must ensure that these functions are not relocated or pre-evaluated and that its results are not cached when compiling and evaluating the query and serializing its results.
A suite of test-cases for all the functions defined in this module, in [QT3] format, is defined at [Test-suite].
This specification follows the general remarks on and terminology for conformance given in Section 1.2 ConformanceFO
In this document, text labeled as an example or as a note is provided for explanatory purposes and is not normative.
The functions defined in this document are contained exclusively in the namespace
http://expath.org/ns/file
and referenced using a
xs:QName
binding to that namespace.
This document uses the prefix file
to refer to this namespace.
User-written applications can choose a different prefix to refer to the
namespace, so long as it is bound to the correct URI. In accordance with current
practice, it is recommended that the prefix file
be reserved for
use with this namespace.
Each function (or group of functions having the same name) is defined in this specification using a standard proforma, full details of which can be found in Section 1.5 Function signatures and descriptionsFO. In particular in this update (trailing) optional arguments for functions (introduced in XPath 4.0) are used where appropriate in the signatures, rather than multiple-arity signatures as previously.
Returns the name of a file or directory.
file:name ( |
||
$path |
as
|
|
) as
|
This function is deterministicFO, context-independentFO, and focus-independentFO.
Returns the name of a file or directory. An empty string is returned if the path points to the root directory, or if it contains no directory separators.
This function is deterministicFO: the path is neither checked for correctness nor looked up in the file system.
Returns the last modification time of a file or directory.
file:last-modified ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns an xs:dateTime
item representing the last modification of
a file or directory.
[file:not-found] is raised if the specified path does not exist.
[file:io-error] is raised if any other error occurs.
Returns the size of a file or directory.
file:size ( |
||
$path |
as , |
|
$recursive |
as
|
:= false() |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
If $path
points to a regular file, returns the byte size of this file.
Otherwise, if it points to a directory, returns either 0
or,
if $recursive
is true
, the aggregated size of all files and
subdirectories.
[file:not-found] is raised if the specified path does not exist.
[file:io-error] is raised if any other error occurs.
Tests if a file or directory exists.
file:exists ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns true
if $path
points to a file or directory,
false
otherwise.
On a UNIX-based system, the root and the volume roots are considered directories.
Tests if $path
points to a directory.
file:is-dir ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns true
if $path
points to an existing directory.
Otherwise, if it points to a regular file or if the file does not exist,
it returns false
.
On a UNIX-based system, the root and the volume roots are considered directories.
Tests if $path
points to a regular file.
file:is-file ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns true
if $path
points to a regular file.
Otherwise, if it points to a directory or if the file does not exist,
it returns false
.
Tests if $path
points to a symbolic link.
file:is-link ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns true
if $path
points to a symbolic link.
Otherwise, if it points to a directory or if the file does not exist,
it returns false
.
Tests if $path
is absolute.
file:is-absolute ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns true
if $path
is absolute,
false
otherwise.
A path is absolute if it does not need to be combined with other path information, such as the current directory, to locate a file.
Note:
All UNC file names are absolute.
Copies a file or a directory.
file:copy ( |
||
$source |
as , |
|
$target |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Copies a file or a directory given a source and a target path/URI.
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
all files of the source directory are copied 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.
Other cases will result in one of the errors listed below.
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.
[file:not-found] is raised if the specified path does not exist.
[file:exists] is raised if the specified source path points to a directory and target path points to an existing file.
[file:no-dir] is raised if the parent directory of the specified source path does not exist.
[file:is-dir] is raised if the specified source path points to a file and the target path points to a directory in which a subdirectory exists with the name of the source file.
[file:io-error] is raised if any other error occurs.
Creates a directory.
file:create-dir ( |
||
$dir |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Creates a directory, or does nothing if the directory already exists. The operation will also create non-existing parent directories.
The function returns the empty sequence if the operation is successful.
[file:exists] is raised if the specified path, or any of its parent directories, points to an existing file.
[file:io-error] is raised if any other error occurs.
Creates a temporary directory.
file:create-temp-dir ( |
||
$prefix |
as
|
:= () , |
$suffix |
as
|
:= () , |
$dir |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
If $dir
is omitted or an empty sequence, the directory will be created
inside the system-dependent default temporary-file directory.
Note:
The created directory will not be deleted automatically after query execution.
[file:no-dir] is raised if the specified directory does not exist or points to a file.
[file:io-error] is raised if any other error occurs.
Creates a temporary file.
file:create-temp-file ( |
||
$prefix |
as
|
:= () , |
$suffix |
as
|
:= () , |
$dir |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Creates a 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.
If $dir
is omitted or an empty sequence, the file will be created inside
the system-dependent default temporary-file directory.
Note:
The created file will not be deleted automatically after query execution.
[file:no-dir] is raised if the specified does not exist or points to a file.
[file:io-error] is raised if any other error occurs.
Deletes a file or a directory.
file:delete ( |
||
$path |
as , |
|
$recursive |
as
|
:= false() |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Deletes a file or a directory from the file system.
If $recursive
is true
, subdirectories will be deleted as well.
The function returns the empty sequence if the operation is successful.
[file:not-found] is raised if the specified path does not exist.
[file:is-dir] is raised if the specified path points to a non-empty directory.
[file:io-error] is raised if any other error occurs.
Moves a file or a directory.
file:move ( |
||
$source |
as , |
|
$target |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Moves a file or a directory given a source and a target path/URI.
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
all files of the source directory 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 [file:is-dir] is raised.
Other cases will result in one of the errors listed below.
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.
[file:not-found] is raised if the specified source path does not exist.
[file:exists] is raised if the specified source path points to a directory and target path points to an existing file.
[file:no-dir] is raised if the parent directory of the specified source path does not exist.
[file:is-dir] is raised if the specified target path points to a directory in which a subdirectory exists with the name of the source.
[file:io-error] is raised if any other error occurs.
Appends a serialized value to a file.
file:append ( |
||
$file |
as , |
|
$value |
as , |
|
$options |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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 Section 15.1.3 fn:serializeFO.
In contrast to fn:serialize
, the encoding stage will not be skipped by
this function.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified file does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:io-error] is raised if any other error occurs.
Appends binary data to a file.
file:append-binary ( |
||
$file |
as , |
|
$value |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:io-error] is raised if any other error occurs.
Appends a string to a file.
file:append-text ( |
||
$file |
as , |
|
$value |
as , |
|
$encoding |
as
|
:= 'utf-8' |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Appends a string to a file.
If the file pointed to by $file
does not exist, a new file will be
created.
If no encoding is supplied, utf-8
is used as output encoding.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:unknown-encoding] is raised if the specified encoding is invalid or not supported by the implementation.
[file:io-error] is raised if any other error occurs.
Appends a sequence of strings to a file, each followed by the system-dependent newline character.
file:append-text-lines ( |
||
$file |
as , |
|
$lines |
as , |
|
$encoding |
as
|
:= 'utf-8' |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Appends a sequence of strings to a file, each followed by the system-dependent
newline character.
If the file pointed to by $file
does not exist, a new file will be created.
If no encoding is supplied, utf-8
is used as output encoding.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:unknown-encoding] is raised if the specified encoding is invalid or not supported by the implementation.
[file:io-error] is raised if any other error occurs.
Returns the binary content of a file.
file:read-binary ( |
||
$file |
as , |
|
$offset |
as
|
:= 0 , |
$length |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns the content of a file as an xs:base64Binary
item.
Chunks of a file can be read by supplying $offset
and $length
.
If no value is supplied for $length
, all remaining bytes will be read.
[file:not-found] is raised if the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:out-of-range] is raised if the specified offset or length value is negative, or if the value would exceed the file bounds.
[file:io-error] is raised if any other error occurs.
Returns the content of a file as a string.
file:read-text ( |
||
$file |
as , |
|
$encoding |
as
|
:= 'utf-8' , |
$fallback |
as
|
:= false() |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns the content of a file in its string representation. Newlines are normalized: Any U+000D (CARRIAGE RETURN) character, optionally followed by a U+000A (NEWLINE) character, is converted to a single U+000A (NEWLINE) character.
If no encoding is supplied, utf-8
is used as input encoding.
By default, invalid XML characters will be rejected. If $fallback
is
true
, the characters will be replaced with the Unicode replacement character
U+FFFD (REPLACEMENT CHARACTER, �
) .
[file:not-found] is raised if the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:unknown-encoding] is raised if the specified encoding is invalid or not supported by the implementation.
[file:io-error] is raised if any other error occurs.
Returns the contents of a file as a sequence of strings, separated at newline boundaries.
file:read-text-lines ( |
||
$file |
as , |
|
$encoding |
as
|
:= 'utf-8' , |
$fallback |
as
|
:= false() |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns the contents of a file as a sequence of strings, separated at newline boundaries.
The newline handling is the same as for Section 14.6.6 fn:unparsed-text-linesFO.
If no encoding is supplied, utf-8
is used as input encoding.
By default, invalid XML characters will be rejected. If $fallback
is enabled,
the characters will be replaced with the Unicode replacement character
U+FFFD (REPLACEMENT CHARACTER, �
) .
[file:not-found] is raised if the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:unknown-encoding] is raised if the specified encoding is invalid or not supported by the implementation.
[file:io-error] is raised if any other error occurs.
Writes a serialized value to a file.
file:write ( |
||
$file |
as , |
|
$value |
as , |
|
$options |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Serializes a value and appends 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 Section 15.1.3 fn:serializeFO.
In contrast to fn:serialize
, the encoding stage will not be skipped by
this function.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:io-error] is raised if any other error occurs.
Expression: |
|
---|---|
Result: |
(Writes numbers to a specified file). |
Expression: |
file:write( 'numbers.json', map:build(1 to 10, string#1), { 'method': 'json' } ) |
Result: |
(Writes a map, serialized as JSON, to a specified file.) |
Writes binary data to a file.
file:write-binary ( |
||
$file |
as , |
|
$value |
as , |
|
$offset |
as
|
:= 0 |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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
is specified and not set to an empty
sequence, data will be written starting at this file position. An existing file may
be resized by such an operation.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:out-of-range] is raised if the specified offset is negative, or if it exceeds the current file size.
[file:io-error] is raised if any other error occurs.
Writes a string to a file.
file:write-text ( |
||
$file |
as , |
|
$value |
as , |
|
$encoding |
as
|
:= 'utf-8' |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Writes a string to a file.
If the file pointed to by $file
already exists, it will be overwritten.
If no encoding is supplied, utf-8
is used as output encoding.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:unknown-encoding] is raised if the specified encoding is invalid or not supported by the implementation.
[file:io-error] is raised if any other error occurs.
Writes strings to a file.
file:write-text-lines ( |
||
$file |
as , |
|
$values |
as , |
|
$encoding |
as
|
:= 'utf-8' |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Writes strings to a file, each followed by the system-dependent newline character.
If the file pointed to by $file
already exists, it will be overwritten;
otherwise, it will be created.
If no encoding is supplied, utf-8
is used as output encoding.
The function returns the empty sequence if the operation is successful.
[file:no-dir] is raised if the parent directory of the specified path does not exist.
[file:is-dir] is raised if the specified path points to a directory.
[file:unknown-encoding] is raised if the specified encoding is invalid or not supported by the implementation.
[file:io-error] is raised if any other error occurs.
Returns the parent directory of a given path.
file:parent ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Transforms the given path into an absolute path, as specified by file:resolve-path, and returns the parent directory.
An empty sequence is returned if the path points to a root directory.
Note:
The inverse function is file:children.
Returns the paths of all files and directories that are located in the given directory.
file:children ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
Note:
The inverse function is file:parent; a related function is file:list.
[file:not-found] is raised if the specified path does not exist.
[file:no-dir] is raised if the specified path does not point to an existing directory.
[file:io-error] is raised if any other error occurs.
Expression: |
|
---|---|
Result: |
( Returns the paths to large videos located in a specific directory. ). |
Returns the paths of all files and directories that are located in the given directory and its subdirectories.
file:descendants ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
[file:not-found] is raised if the specified path does not exist.
[file:no-dir] is raised if the specified path does not point to an existing directory.
[file:io-error] is raised if any other error occurs.
Expression: |
|
---|---|
Result: |
( Returns the paths to all subdirectories located in a specific directory. ). |
Lists all files and directories in a given directory.
file:list ( |
||
$dir |
as , |
|
$recursive |
as
|
:= false() , |
$pattern |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Lists all files and directories in a given directory.
In contrast to is file:children,
the returned paths are relative to the supplied directory $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.
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 must support at least the following glob syntax characters:
*
for matching any number of unknown characters and
?
for matching one unknown character.
Note:
A related function is file:children.
[file:not-found] is raised if the specified path does not exist.
[file:no-dir] is raised if the specified path does not point to an existing directory.
[file:io-error] is raised if any other error occurs.
Expression: |
let $root := '/path/to/files/' for $file in file:list($root, true(), '*.txt') let $path := file:resolve-path($file, $root) where file:size($path) > 1000000 return file:read-text($path) |
---|---|
Result: |
(Returns the contents of large text files located in a specific directory and its subdirectories.) |
Lists all root directories of the file system.
file:list-roots () as xs:string* |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
Note:
Dynamically available UNC file names are not returned by this function.
Transforms a relative path into an absolute operating system path.
file:resolve-path ( |
||
$path |
as , |
|
$base |
as
|
:= () |
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Transforms a relative path into an absolute operating system path by resolving it
against the current working directory. If the path is relative, and if an
absolute $base
path is specified, it will be resolved against this path.
If the resulting path points to a directory, it will be suffixed with the system-specific directory separator.
Expression | Result |
---|---|
|
'C:/Windows/INF/' (The result refers to a Windows system.) |
|
'C:/data.bin' (The result refers to a Windows system.) |
|
'/home/hilda/notes.txt' (The result refers to a UNIX-based system.) |
Transforms a path to a canonical representation.
file:path-to-native ( |
||
$path |
as
|
|
) as
|
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Transforms a URI, an absolute path, or relative path to a canonical, system-dependent 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 system-specific directory separator.
[file:not-found] is raised if the specified path does not exist.
[file:io-error] is raised if an error occurs while trying to generate the native path.
Transforms a file system path into a URI.
file:path-to-uri ( |
||
$path |
as
|
|
) as
|
This function is deterministicFO, context-independentFO, and focus-independentFO.
Transforms a file system path into a URI with the file
scheme. If the
path is relative, it is first resolved against the current working directory.
This function is deterministicFO: the path is neither checked for correctness nor looked up in the file system.
Returns the directory separator.
file:dir-separator () as xs:string |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
file:line-separator () as xs:string |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
file:path-separator () as xs:string |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
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.
file:temp-dir () as xs:string |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns the path to the default temporary-file directory of an operating system.
Returns the parent directory of the static base URI.
file:base-dir () as xs:string? |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns the parent directory of the static base URI.
If the Base URI property is undefined, the empty sequence is returned.
If a static base URI exists, and if points to a local file path, this function
returns the same result as the expression
file:parent(static-base-uri())
.
Returns the current working directory.
file:current-dir () as xs:string |
This function is nondeterministicFO, context-dependentFO, and focus-independentFO.
Returns the current working directory.
The effect of the function is equivalent to the result of the following XPath expression.
file:resolve-path('.')
The error text provided with these errors is non-normative.
The specified path already exists.
The specified path is invalid.
A generic file system error occurred.
The specified path points to a directory.
The specified path does not point to a directory.
The specified path does not exist.
The specified offset or length is negative, or the chosen values would exceed the file bounds.
The specified encoding is not supported.
This Appendix describes some sources of functions or operators that fall outside the scope of the function library defined in this specification. It includes both function specifications and function implementations. Inclusion of a function in this appendix does not constitute any kind of recommendation or endorsement; neither is omission from this appendix to be construed negatively. This Appendix does not attempt to give any information about licensing arrangements for these function specifications or implementations.
A number of W3C Recommendations make use of XPath, and in some cases such Recommmendations define additional functions to be made available when XPath is used in a specific host language.
Use the arrows to browse significant changes since the 1.0 version of this specification.
See 1 Introduction
Sections with significant changes are marked Δ in the table of contents. New functions introduced in this version are marked ➕ in the table of contents.
See 1 Introduction
PR TODO
New in 4.0.
$fallback
parameter added.
New in 4.0.
$base
parameter added.
The function signatures of all the specified signatures now use the “optional argument” syntax of XPath 4.0 where appropriate, rather than giving several signatures of differing arity. Other than that, no intended change to the semantics of the functions are assumed.
These changes are not highlighted in the change-marked version of the specification.
This section summarizes the extent to which this specification is compatible with previous versions.
Version 4.0 of this function library is fully backwards compatible with version 1.0, except as noted below:
The use of optional arguments in the function signatures means that minor alterations to possible function calls, which would be invalid in 1.0, are now supported. For example:
file:list($dir, false(), ())
would be invalid in 1.0, as the third argument $pattern
is
defined to be of type xs:string
. It is valid for 4.0, as the
empty sequence denotes default behavior of listing all files.
The functions file:append
, file:append-text
, file:append-text-lines
file:create-temp-dir
, file:create-temp-file
,
file:delete
, file:read-binary
,
file:read-text
, file:read-text-lines
,
file:write
, file:write-binary
,
file:write-text
and file:write-text-lines
all have
similar incompatibilities.