W3C

EXPath File Module 4.0

W3C Editor's Draft 5 December 2024

This version:
https://qt4cg.org/pr/1636/EXPath/file-40/
Latest version of EXPath File Module 4.0:
https://qt4cg.org/specifications/EXPath/file-40/
Most recent Recommendation of EXPath File Module:
http://expath.org/spec/file
Editors:
Christian Grün, BaseX GmbH
Matthias Brantner, 28msec GmbH
Gabriel Petrovay, 28msec GmbH

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 using HTML5 vocabulary and XML function catalog.


Abstract

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.

Status of this Document

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.


1 Introduction

Changes in 4.0

  1. Use the arrows to browse significant changes since the 1.0 version of this specification.

  2. 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 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:

References to specific sections of some 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] .

1.1 Error management

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.

1.2 File Paths

All file paths are specified as strings, and are resolved against the current working directory. The current working directory is implementation-defined: It can e. g. 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-definedFO40 representation (which usually is the representation of the underlying operating system).

It is implementation-definedFO40 as to whether the error [file:invalid-path] is raised if a path is invalid.

Editorial note  
Should raising this error perhaps be implementation-dependentFO40?

If a function returns a string that refers to a directory, it will always be 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 $dir := file:base-dir() 
let $path := concat($dir, $filename)
return file:read-text($path)

1.3 Function Execution

Almost all of these functions are marked as nondeterministicFO40, which means they are not guaranteed to perform the same operations and produce identical results from repeated calls. 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.

1.4 Test suite

A suite of test-cases for all the functions defined in this module, in [QT3] format, is defined at [Test-suite].

1.5 Conformance

This specification follows the general remarks on and terminology for conformance given in Section 1.2 ConformanceFO40

In this document, text labeled as an example or as a note is provided for explanatory purposes and is not normative.

1.6 Namespaces and prefixes

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.

1.7 Function signatures and descriptions

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 descriptionsFO40. 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.

2 File Properties

2.1 file:exists

Summary

Tests if a file or directory exists.

Signature
file:exists(
$path as xs:string
) as xs:boolean
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns true if $path points to a file or directory, false otherwise.

On UNIX-based systems the root and the volume roots are considered directories.

2.2 file:is-dir

Summary

Tests if $path points to a directory.

Signature
file:is-dir(
$path as xs:string
) as xs:boolean
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns true if $path points to a directory, false otherwise.

On UNIX-based systems the root and the volume roots are considered directories.

2.3 file:is-file

Summary

Tests if $path points to a file.

Signature
file:is-file(
$path as xs:string
) as xs:boolean
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns true if $path points to a existing file.

Returns false if $path points to a existing directory.

Otherwise returns false

2.4 file:last-modified

Summary

Returns the last modification time of a file or directory.

Signature
file:last-modified(
$path as xs:string
) as xs:dateTime
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the last modification time of a file or directory.

Error Conditions

[file:not-found] is raised if $path does not exist.

[file:io-error] is raised if any other error occurs.

2.5 file:size

Summary

Returns the byte size of a file, or the value 0 for directories.

Signature
file:size(
$file as xs:string
) as xs:integer
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns 0 if $file points to a directory.

Returns the byte size of the file $file, if it exists.

Error Conditions

[file:not-found] is raised if $path does not exist.

[file:io-error] is raised if any other error occurs.

3 Manipulation of Files as Entities

3.1 file:copy

Summary

Copies a file or a directory given a source and a target path/URI.

Signature
file:copy(
$source as xs:string,
$target as xs:string
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Copies a file or a directory given a source and a target path/URI. The following cases may occur if $source points to a file:

  1. if $target does not exist, it will be created.

  2. if $target is a file, it will be overwritten.

  3. 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.

The following cases may occur if $source points to a directory:

  1. 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.

  2. 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 raise one of the errors listed below.

The function returns the empty sequence if the operation is successful. If an error occurs during the operation, no rollback to the original state will be possible

Error Conditions

[file:not-found] is raised if the $source path does not exist.

[file:exists] is raised if $source points to a directory and $target points to an existing file.

[file:no-dir] is raised if the parent directory of $source does not exist.

[file:is-dir] is raised if $source points to a file and $target 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.

3.2 file:create-dir

Summary

Creates a directory if it does not already exist.

Signature
file:create-dir(
$dir as xs:string
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Creates a directory, or does nothing if the directory already exists. The operation will create all non-existing parent directories.

The function returns the empty sequence if the operation is successful.

Error Conditions

[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.

3.3 file:create-temp-dir

Summary

Creates a temporary directory.

Signature
file:create-temp-dir(
$prefix as xs:string,
$suffix as xs:string,
$dir as xs:string? := ()
) as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Creates a temporary directory and all non-existing parent directories and returns the full path to the created directory.

The temporary directory will not be automatically deleted after query execution. It is guaranteed to not already exist when the function is called.

If $dir is omitted or an empty sequence, the directory will be created inside the system-dependent default temporary-file directory.

Error Conditions

[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.

3.4 file:create-temp-file

Summary

Creates a temporary file.

Signature
file:create-temp-file(
$prefix as xs:string,
$suffix as xs:string,
$dir as xs:string? := ()
) as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Creates a temporary file and all non-existing parent directories and returns the full path to the created file.

The temporary file will not be automatically deleted after query execution. It is guaranteed to not already exist when the function is called.

If $dir is omitted or an empty sequence, the file will be created inside the system-dependent default temporary-file directory.

Error Conditions

[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.

3.5 file:delete

Summary

Deletes a file or a directory from the file system.

Signature
file:delete(
$path as xs:string,
$recursive as xs:boolean? := false()
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Deletes a file or a directory from the file system.

If the optional parameter $recursive is true, sub-directories will be deleted as well.

The function returns the empty sequence if the operation is successful.

Error Conditions

[file:not-found] is raised if $path does not exist.

[file:is-dir] is raised if $file points to a non-empty directory.

[file:io-error] is raised if any other error occurs.

3.6 file:list

Summary

Lists all files and directories in a given directory.

Signature
file:list(
$dir as xs:string,
$recursive as xs:boolean? := false(),
$pattern as xs:string? := ()
) as xs:string*
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Lists all files and directories in a given directory. The order of the items in the resulting sequence is not defined. The "." and ".." items are never returned. The returned paths are relative to the provided directory $dir.

If the optional parameter $recursive is true, all directories and files will be returned that are found while recursively traversing the given directory. If $recursive is omitted or an empty sequence or false only the contents of the specified directory will be returned.

The optional $pattern parameter defines a name pattern in the glob syntax. If this is provided and is not an empty sequence, 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 for the pattern:

  • * for matching any number of unknown characters and

  • ? for matching one unknown character.

A related function is file:children.

Error Conditions

[file:no-dir] is raised if $dir does not point to an existing directory.

[file:io-error] is raised if any other error occurs.

3.7 file:move

Summary

Moves a file or a directory.

Signature
file:move(
$source as xs:string,
$target as xs:string
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Moves a file or a directory given a source and a target path/URI. The following cases may occur if $source points to a file:

  1. if $target does not exist, it will be created.

  2. if $target is a file, it will be overwritten.

  3. 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.

The following cases may occur if $source points to a directory:

  1. 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.

  2. 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 raise one of the errors listed below.

The function returns the empty sequence if the operation is successful. If an error occurs during the operation, no rollback to the original state will be possible

Error Conditions

[file:not-found] is raised if the $source path does not exist.

[file:exists] is raised if $source points to a directory and $target points to an existing file.

[file:no-dir] is raised if the parent directory of $source does not exist.

[file:is-dir] is raised if $target 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.

4 Input/Output

4.1 file:append

Summary

Appends a sequence of items to a file. If the file pointed by $file does not exist, a new file will be created.

Signature
file:append(
$file as xs:string,
$items as item()*,
$params as element(output:serialization-parameters)? := ()
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Appends a sequence of items to a file.

If the file pointed by $file does not exist, a new file will be created.

$params, if not an empty sequence, controls the way the $items items are serialized. The semantics of $params are those of the same argument of Section 14.1.3 fn:serializeFO40, consisting of an output:serialization-parameters element whose format is defined in Section 3.1 Setting Serialization Parameters by Means of a Parameter DocumentSE40. 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.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:io-error] is raised if any other error occurs.

4.2 file:append-binary

Summary

Appends a Base64 item as binary data to a file.

Signature
file:append-binary(
$file as xs:string,
$value as xs:base64Binary
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Appends a Base64 item as binary data 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.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:io-error] is raised if any other error occurs.

4.3 file:append-text

Summary

Appends a string to a file.

Signature
file:append-text(
$file as xs:string,
$value as xs:string,
$encoding as xs:string? := 'utf-8'
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Appends a string to the file $file.

If the file pointed to by $file does not exist, a new file will be created.

The optional parameter $encoding, if omitted or an empty sequence, is considered to be UTF-8.

The function returns the empty sequence if the operation is successful.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:unknown-encoding] is raised if $encoding is invalid or not supported by the implementation.

[file:io-error] is raised if any other error occurs.

4.4 file:append-text-lines

Summary

Appends a sequence of strings to a file, each followed by the system-dependent newline character.

Signature
file:append-text-lines(
$file as xs:string,
$lines as xs:string*,
$encoding as xs:string? := 'utf-8'
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

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.

The optional parameter $encoding, if omitted or an empty sequence, is considered to be UTF-8.

The function returns the empty sequence if the operation is successful.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:unknown-encoding] is raised if $encoding is invalid or not supported by the implementation.

[file:io-error] is raised if any other error occurs.

4.5 file:read-binary

Summary

Returns the content of a file in its Base64 representation.

Signature
file:read-binary(
$file as xs:string,
$offset as xs:integer? := 0,
$length as xs:integer? := ()
) as xs:base64Binary
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the content of a file in its Base64 representation.

The optional parameters $offset and $length can be used to read chunks of a file.

Error Conditions

[file:not-found] is raised if $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:out-of-range] is raised if $offset or $length is negative, or if the chosen values would exceed the file bounds.

[file:io-error] is raised if any other error occurs.

4.6 file:read-text

Summary

Returns the content of a file in its string representation.

Signature
file:read-text(
$file as xs:string,
$encoding as xs:string? := 'utf-8'
) as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the content of a file in its string representation.

The optional parameter $encoding, if omitted or an empty sequence, is considered to be UTF-8.

Error Conditions

[file:not-found] is raised if $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:unknown-encoding] is raised if $encoding is invalid or not supported by the implementation.

[file:io-error] is raised if any other error occurs.

4.7 file:read-text-lines

Summary

Returns the contents of a file as a sequence of strings, separated at newline boundaries.

Signature
file:read-text-lines(
$file as xs:string,
$encoding as xs:string? := 'utf-8'
) as xs:string*
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the contents of a file as a sequence of strings, separated at newline boundaries.

The optional parameter $encoding, if omitted or an empty sequence, is considered to be UTF-8.

The newline handling is the same as for Section 13.6.6 fn:unparsed-text-linesFO40.

Error Conditions

[file:not-found] is raised if $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:unknown-encoding] is raised if $encoding is invalid or not supported by the implementation.

[file:io-error] is raised if any other error occurs.

4.8 file:write

Summary

Writes a sequence of items to a file.

Signature
file:write(
$file as xs:string,
$items as item()*,
$params as element(output:serialization-parameters)? := ()
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Writes a sequence of items to a file.

If $file already exists, it will be overwritten; otherwise, it will be created.

$params, if not an empty sequence, controls the way the $items items are serialized. The semantics of $params are those of the same argument of Section 14.1.3 fn:serializeFO40, consisting of an output:serialization-parameters element whose format is defined in Section 3.1 Setting Serialization Parameters by Means of a Parameter DocumentSE40. 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.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:io-error] is raised if any other error occurs.

4.9 file:write-binary

Summary

Writes a Base64 item as binary to a file.

Signature
file:write-binary(
$file as xs:string,
$value as xs:base64Binary,
$offset as xs:integer? := 0
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Writes a Base64 item as binary to a file.

If $file already exists, it will be overwritten; otherwise, it will be created.

If the optional parameter $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.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:out-of-range] is raised if $offset is negative, or if it exceeds the current file size.

[file:io-error] is raised if any other error occurs.

4.10 file:write-text

Summary

Writes a string to a file.

Signature
file:write-text(
$file as xs:string,
$value as xs:string,
$encoding as xs:string? := 'utf-8'
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Writes a strings to a file.

If $file already exists, it will be overwritten.

The optional parameter $encoding, if omitted or an empty sequence, is considered to be UTF-8.

The function returns the empty sequence if the operation is successful.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:unknown-encoding] is raised if $encoding is invalid or not supported by the implementation.

[file:io-error] is raised if any other error occurs.

4.11 file:write-text-lines

Summary

Writes a sequence of strings to a file, each followed by the system-dependent newline character.

Signature
file:write-text-lines(
$file as xs:string,
$values as xs:string*,
$encoding as xs:string? := 'utf-8'
) as empty-sequence()
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Writes a sequence of strings to a file, each followed by the system-dependent newline character.

If $file already exists, it will be overwritten; otherwise, it will be created.

The optional parameter $encoding, if omitted or an empty sequence, is considered to be UTF-8.

The function returns the empty sequence if the operation is successful.

Error Conditions

[file:no-dir] is raised if the parent directory of $file does not exist.

[file:is-dir] is raised if $file points to a directory.

[file:unknown-encoding] is raised if $encoding is invalid or not supported by the implementation.

[file:io-error] is raised if any other error occurs.

5 Paths

None of the functions in this section performs any check regarding the existence of the received or returned paths.

5.1 file:name

Summary

Returns the name of a file or directory.

Signature
file:name(
$path as xs:string
) as xs:string
Properties

This function is deterministicFO40, context-independentFO40, and focus-independentFO40.

Rules

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 deterministicFO40 (no path existence check is made).

5.2 file:parent

Summary

Returns the parent directory of a given path.

Signature
file:parent(
$path as xs:string
) as xs:string?
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Transforms the given path into an absolute path, as specified by file:resolve-path, and returns the parent directory.

The inverse function is file:children.

An empty sequence is returned if the path points to a root directory.

5.3 file:children

Summary

Returns the paths of all files and directories that are located in the given directory.

Signature
file:children(
$path as xs:string
) as xs:string*
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

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 "." and ".." items are never returned.

The inverse function is file:parent; a related function is file:list.

Error Conditions

[file:no-dir] is raised if $path does not point to an existing directory.

[file:io-error] is raised if any other error occurs.

5.4 file:path-to-native

Summary

Transforms a URI, an absolute path, or relative path to a canonical, system-dependent path representation.

Signature
file:path-to-native(
$path as xs:string
) as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

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.

Error Conditions

[file:not-found] is raised if $path does not exist.

[file:io-error] is raised if an error occurs while trying to obtain the native path.

5.5 file:path-to-uri

Summary

Transforms a file system path into a URI.

Signature
file:path-to-uri(
$path as xs:string
) as xs:anyURI
Properties

This function is deterministicFO40, context-independentFO40, and focus-independentFO40.

Rules

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 deterministicFO40 (no path existence check is made).

5.6 file:resolve-path

Summary

Transforms a relative path into an absolute operating system path.

Signature
file:resolve-path(
$path as xs:string
) as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Transforms a relative path into an absolute operating system path by resolving it against the current working directory.

If the resulting path points to a directory, it will be suffixed with the system-specific directory separator.

6 System Properties

6.1 file:dir-separator

Summary

Returns the value of the operating system-specific directory separator.

Signature
file:dir-separator() as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the value of the operating system-specific directory separator, which usually is / on UNIX-based systems and \ on Windows systems.

6.2 file:line-separator

Summary

Returns the value of the operating system-specific line separator.

Signature
file:line-separator() as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the value of the operating system-specific line separator, which usually is 
 on UNIX-based systems, 
 on Windows systems and 
 on Mac systems.

6.3 file:path-separator

Summary

Returns the value of the operating system-specific path separator.

Signature
file:path-separator() as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the value of the operating system-specific path separator, which usually is : on UNIX-based systems and ; on Windows systems.

6.4 file:temp-dir

Summary

Returns the path to the default temporary-file directory of an operating system.

Signature
file:temp-dir() as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the path to the default temporary-file directory of an operating system.

6.5 file:base-dir

Summary

Returns the parent directory of the static base URI.

Signature
file:base-dir() as xs:string?
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

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()).

6.6 file:current-dir

Summary

Returns the current working directory.

Signature
file:current-dir() as xs:string
Properties

This function is nondeterministicFO40, context-dependentFO40, and focus-independentFO40.

Rules

Returns the current working directory.

Formal Specification

The effect of the function is equivalent to the result of the following XPath expression.

file:resolve-path('.')

A References

A.1 Normative references

EXPath File 1.0
File Module 1.0. Christian Grün, Matthias Brantner and Gabriel Petrovay, editors. EXPath Module 20 February 2015.
IEEE 754-1985
IEEE 754-2019
IEEE. IEEE Standard for Floating-Point Arithmetic.
XML Path Language (XPath) 2.0
XML Path Language (XPath) 2.0 (Second Edition), Don Chamberlin, Anders Berglund, Scott Boag, et. al., Editors. World Wide Web Consortium, 14 December 2010. This version is https://www.w3.org/TR/2010/REC-xpath20-20101214/. The latest version is available at https://www.w3.org/TR/xpath20/.
XQuery and XPath Functions and Operators 4.0
XQuery and XPath Functions and Operators 4.0, XSLT Extensions Community Group, World Wide Web Consortium.
XML Path Language (XPath) 4.0
XSL Transformations (XSLT) Version 4.0
CITATION: T.B.D.
XQuery and XPath Data Model (XDM) 4.0
XQuery and XPath Data Model (XDM) 4.0, XSLT Extensions Community Group, World Wide Web Consortium.
XSLT and XQuery Serialization 3.0
XSLT and XQuery Serialization 3.0. Henry Zongaro, et al. W3C Recommendation 08 April 2014.
XQuery and XPath Functions and Operators 3.0
XPath and XQuery Functions and Operators 3.0. Michael Kay. W3C Recommendation 08 April 2014.
XQuery 4.1: An XML Query Language
CITATION: T.B.D.
XML Schema Part 2: Datatypes Second Edition
XML Schema Part 2: Datatypes Second Edition, Oct. 28 2004. Available at: http://www.w3.org/TR/xmlschema-2/

A.2 Non-normative references

Test-suite
The test suite for this module, using QT3 format, is in the EXPath repository http://github.com/expath/expath-cg in the directory tests/qt3/file/
QT3
XML Query Test Suite. W3C 21 June 2013.
EXPath
EXPath: Collaboratively Defining Open Standards for Portable XPath Extensions. http://expath.org/.

B Error summary

The error text provided with these errors is non-normative.

file:exists

The specified path already exists.

file:invalid-path

The specified path is invalid.

file:io-error

A generic file system error occurred.

file:is-dir

The specified path points to a directory.

file:no-dir

The specified path does not point to a directory.

file:not-found

The specified path does not exist.

file:out-of-range

The specified offset or length is negative, or the chosen values would exceed the file bounds.

file:unknown-encoding

The specified encoding is not supported.

C Glossary (Non-Normative)

D Other Functions (Non-Normative)

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.

D.1 XPath Functions and Operators Defined in Other W3C Recommendations

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.

D.1.1 Functions and Operators Defined in XPath and XQuery Functions and Operators

E Checklist of implementation-defined features (Non-Normative)

    F Changes since version 1.0 (Non-Normative)

    F.1 Summary of Changes

    1. Use the arrows to browse significant changes since the 1.0 version of this specification.

      See 1 Introduction

    2. 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

    F.2 Changes to Function Signatures

    1. 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.

    F.3 Editorial Changes

    These changes are not highlighted in the change-marked version of the specification.

    G Compatibility with Previous Versions (Non-Normative)

    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:

    1. 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 behaviour, that is all files are listed.

      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.