http://expath.org/ns/file

View as XML or JSON.

This module implements the file API EXPath specification available at http://expath.org/spec/file

Function Summary

append-binary ($file as xs:string, $content as xs:base64Binary) as empty-sequence() external

Appends a sequence of Base64 items as binary to a file.

append-text-lines ($file as xs:string, $content as xs:string*) as empty-sequence()

Appends a sequence of string to a file, each followed by a platform-dependent newline character(s), using the UTF-8 character encoding.

append-text-lines ($file as xs:string, $content as xs:string*, $encoding as xs:string) as empty-sequence() external

Appends a sequence of string items to a file, each followed by a platform-dependent newline character(s).

append-text ($file as xs:string, $content as xs:string) as empty-sequence()

Appends a sequence of string items to a file.

append-text ($file as xs:string, $content as xs:string, $encoding as xs:string) as empty-sequence() external

Appends a sequence of string items to a file.

base-name ($path as xs:string) as xs:string external

Returns the last component from the $path , deleting any trailing directory-separator characters.

base-name ($path as xs:string, $suffix as xs:string) as xs:string

Returns the last component from the $path , deleting any trailing directory-separator characters and the $suffix .

copy ($source as xs:string, $destination as xs:string) as empty-sequence()

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

create-directory ($dir as xs:string) as empty-sequence() external

Creates a directory.

delete ($path as xs:string) as empty-sequence()

Deletes a file or a directory from the file system.

dir-name ($path as xs:string) as xs:string external

This function is the converse of file:base-name .

directory-separator () as xs:string external

This function returns the value of the operating system specific directory separator.

exists ($path as xs:string) as xs:boolean

Tests if a path/URI is already used in the file system.

exists ($path as xs:string, $follow-symlinks as xs:boolean) as xs:boolean external

Tests if a path/URI is already used in the file system.

glob-to-regex ($pattern as xs:string) as xs:string

A helper function that performs a trivial (not complete) glob to regex pattern translation.

is-directory ($path as xs:string) as xs:boolean external

Tests if a path/URI points to a directory.

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

Tests if a path/URI points to a file.

is-symlink ($path as xs:string) as xs:boolean external

Tests if a path/URI points to symbolic link.

last-modified ($path as xs:string) as xs:dateTime external

Retrieves the timestamp of the last modification of the file system item pointed by the path/URI.

list ($dir as xs:string) as xs:string* external

Lists the file system items in a certain directory.

list ($path as xs:string, $recursive as xs:boolean) as xs:string*

Lists the file system items in a certain directory.

list ($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*

Lists all files matching the given pattern in a given directory.

move ($source as xs:string, $destination as xs:string) as empty-sequence()

Moves a file or directory given a source and a destination paths/URIs.

path-separator () as xs:string external

This function returns the value of the operating system specific path separator.

path-to-native ($path as xs:string) as xs:string external

Transforms a URI, an absolute path, or relative path to a native path on the running platform.

path-to-uri ($path as xs:string) as xs:anyURI external

Transforms a file system path into a URI with the file:// scheme.

read-binary ($file as xs:string) as xs:base64Binary external

Reads the content of a file and returns a Base64 representation of the content.

read-text-lines ($file as xs:string) as xs:string*

Reads the content of a file and returns a sequence of strings representing the lines in the content of the file.

read-text-lines ($file as xs:string, $encoding as xs:string) as xs:string* external

Reads the content of a file using the specified encoding and returns a sequence of strings representing the lines in the content of the file.

read-text ($file as xs:string) as xs:string

Reads the content of a file and returns a string representation of the content.

read-text ($file as xs:string, $encoding as xs:string) as xs:string external

Reads the content of a file using the specified encoding and returns a string representation of the content.

resolve-path ($path as xs:string) as xs:string external

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

size ($file as xs:string) as xs:integer external

Retrieves the size of a file.

write-binary ($file as xs:string, $content as xs:base64Binary) as empty-sequence() external

Writes a sequence of Base64 items as binary to a file.

write-text-lines ($file as xs:string, $content as xs:string*) as empty-sequence()

Writes a sequence of strings to a file, each followed by a platform-dependent newline character(s), using the UTF-8 character encoding.

write-text-lines ($file as xs:string, $content as xs:string*, $encoding as xs:string) as empty-sequence() external

Writes a sequence of strings to a file, each followed by a platform-dependent newline character(s).

write-text ($file as xs:string, $content as xs:string) as empty-sequence()

Writes a sequence of strings to a file using the UTF-8 character encoding.

write-text ($file as xs:string, $content as xs:string, $encoding as xs:string) as empty-sequence() external

Writes a sequence of strings to a file.

Functions

append-binary#2

declare  %an:sequential function file:append-binary($file as xs:string, $content as xs:base64Binary) as empty-sequence() external
Appends a sequence of Base64 items as binary to a file. If the file pointed by
$file
does not exist, a new file will be created.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:base64Binary
The content to be written to the file.

Returns

empty-sequence()
The empty sequence.

append-text-lines#2

declare  %an:sequential function file:append-text-lines($file as xs:string, $content as xs:string*) as empty-sequence()
Appends a sequence of string to a file, each followed by a platform-dependent newline character(s), using the UTF-8 character encoding.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.

Returns

empty-sequence()
The empty sequence.

append-text-lines#3

declare  %an:sequential function file:append-text-lines($file as xs:string, $content as xs:string*, $encoding as xs:string) as empty-sequence() external
Appends a sequence of string items to a file, each followed by a platform-dependent newline character(s).

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.
encoding as xs:string
The character encoding to append $content as.

Returns

empty-sequence()
The empty sequence.

append-text#2

declare  %an:sequential function file:append-text($file as xs:string, $content as xs:string) as empty-sequence()
Appends a sequence of string items to a file.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.

Returns

empty-sequence()
The empty sequence.

append-text#3

declare  %an:sequential function file:append-text($file as xs:string, $content as xs:string, $encoding as xs:string) as empty-sequence() external
Appends a sequence of string items to a file.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.
encoding as xs:string
The character encoding to append $content as.

Returns

empty-sequence()
The empty sequence.

base-name#1

declare  function file:base-name($path as xs:string) as xs:string external
Returns the last component from the
$path
, deleting any trailing directory-separator characters. If
$path
consists entirely directory-separator characters, the empty string is returned. If
$path
is the empty string, the string
"."
is returned, signifying the current directory. No path existence check is made.

Parameters

path as xs:string
A file path/URI.

Returns

xs:string
The base name of this file.

base-name#2

declare  function file:base-name($path as xs:string, $suffix as xs:string) as xs:string
Returns the last component from the
$path
, deleting any trailing directory-separator characters and the
$suffix
. If path consists entirely directory-separator characters, the empty string is returned. If path is the empty string, the string
"."
is returned, signifying the current directory. No path existence check is made. The
$suffix
can be used for example to eliminate file extensions.

Parameters

path as xs:string
A file path/URI.
suffix as xs:string
A suffix which should get deleted from the result.

Returns

xs:string
The base-name of $path with a deleted $suffix.

copy#2

declare  %an:nondeterministic %an:sequential function file:copy($source as xs:string, $destination as xs:string) as empty-sequence()
Copies a file or a directory given a source and a destination path/URI.

Parameters

source as xs:string
The path/URI of the file or directory to copy.
destination as xs:string
The destination path/URI.

Returns

empty-sequence()
The empty sequence.

create-directory#1

declare  %an:sequential function file:create-directory($dir as xs:string) as empty-sequence() external
Creates a directory. The operation is will create all the missing parent directories from the given path.

Parameters

dir as xs:string
The path/URI denoting the directory to be created.

Returns

empty-sequence()
The empty sequence.

delete#1

declare  %an:nondeterministic %an:sequential function file:delete($path as xs:string) as empty-sequence()
Deletes a file or a directory from the file system. If
$path
points to a directory the directory will be deleted recursively.

Parameters

path as xs:string
The path/URI of the file or directory to delete.

Returns

empty-sequence()
The empty sequence.

dir-name#1

declare  function file:dir-name($path as xs:string) as xs:string external
This function is the converse of
file:base-name
. It returns a string denoting the parent directory of the
$path
. Any trailing directory-separator characters are not counted as part of the directory name. If path is the empty string or contains no directory-separator string,
"."
is returned, signifying the current directory. No path existence check is made.

Parameters

path as xs:string
The filename, of which the dirname should be get.

Returns

xs:string
The name of the directory the file is in.

directory-separator#0

declare  function file:directory-separator() as xs:string external
This function returns the value of the operating system specific directory separator. For example,
/
on Unix-based systems and
\
on Windows systems.

Parameters

Returns

xs:string
The operating system specific directory separator.

exists#1

declare  %an:nondeterministic function file:exists($path as xs:string) as xs:boolean
Tests if a path/URI is already used in the file system.

Parameters

path as xs:string
The path/URI to test.

Returns

xs:boolean
true if $path points to an existing file system item; for symbolic links, retuns true if the linked-to item exists.

exists#2

declare  %an:nondeterministic function file:exists($path as xs:string, $follow-symlinks as xs:boolean) as xs:boolean external
Tests if a path/URI is already used in the file system.

Parameters

path as xs:string
The path/URI to test.
follow-symlinks as xs:boolean
if true, follows symbolic links.

Returns

xs:boolean
true if $path points to an existing file system item.

glob-to-regex#1

declare  function file:glob-to-regex($pattern as xs:string) as xs:string
A helper function that performs a trivial (not complete) glob to regex pattern translation.

Parameters

pattern as xs:string
The glob pattern.

Returns

xs:string
A regex pattern corresponding to the glob pattern provided.

is-directory#1

declare  %an:nondeterministic function file:is-directory($path as xs:string) as xs:boolean external
Tests if a path/URI points to a directory. On Unix-based systems, the root and the volume roots are considered directories.

Parameters

path as xs:string
The path/URI to test.

Returns

xs:boolean
true if $path points to a directory; for symbolic links, returns true if the linked-to item is a directory.

is-file#1

declare  %an:nondeterministic function file:is-file($path as xs:string) as xs:boolean external
Tests if a path/URI points to a file.

Parameters

path as xs:string
The path/URI to test.

Returns

xs:boolean
true if $path points to a file; for symbolic links, returns true if the linked-to item is a file.

last-modified#1

declare  %an:nondeterministic function file:last-modified($path as xs:string) as xs:dateTime external
Retrieves the timestamp of the last modification of the file system item pointed by the path/URI.

Parameters

path as xs:string
The file system item to read the last modification timestamp from.

Returns

xs:dateTime
The date and time of the last modification of the item.

list#1

declare  %an:nondeterministic function file:list($dir as xs:string) as xs:string* external
Lists the file system items in a certain directory. The operation is equivalent to calling:
file:list($dir, fn:false())
.

Parameters

dir as xs:string
The path/URI of the directory to retrieve the children from.

Returns

xs:string*
The sequence of names of the direct children.

list#2

declare  %an:nondeterministic function file:list($path as xs:string, $recursive as xs:boolean) as xs:string*
Lists the file system items in a certain directory. The order of the items in the resulting sequence is not defined. The "." and ".." items are not returned. The returned paths are relative to the provided
$path
. If
$recursive
evaluates to
fn:true()
, the operation will recurse in the subdirectories.

Parameters

path as xs:string
recursive as xs:boolean
A boolean flag indicating whether the operation should be performed recursively.

Returns

xs:string*
A sequence of relative paths.

list#3

declare  %an:nondeterministic function file:list($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*
Lists all files matching the given pattern in a given directory. The order of the items in the result is not defined. The "." and ".." items are not considered for the match. The file paths are relative to the provided $path. The pattern is a glob expression supporting:
  • *
    for matching any number of unknown characters
  • ?
    for matching one unknown character

Parameters

path as xs:string
The path/URI to retrieve the children from.
recursive as xs:boolean
A boolean flag indicating whether the operation should be performed recursively.
pattern as xs:string
The file name pattern.

Returns

xs:string*
A sequence of file names matching the pattern.

move#2

declare  %an:sequential function file:move($source as xs:string, $destination as xs:string) as empty-sequence()
Moves a file or directory given a source and a destination paths/URIs.

Parameters

source as xs:string
The path/URI of the file to move.
destination as xs:string
The destination path/URI.

Returns

empty-sequence()
The empty sequence.

path-separator#0

declare  function file:path-separator() as xs:string external
This function returns the value of the operating system specific path separator. For example,
:
on Unix-based systems and
;
on Windows systems.

Parameters

Returns

xs:string
The operating system specific path separator.

path-to-native#1

declare  function file:path-to-native($path as xs:string) as xs:string external
Transforms a URI, an absolute path, or relative path to a native path on the running platform. No path existence check is made.

Parameters

path as xs:string
The uri or path to normalize.

Returns

xs:string
The native path corresponding to
$path
.

path-to-uri#1

declare  function file:path-to-uri($path as xs:string) as xs:anyURI external
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. No path existence check is made.

Parameters

path as xs:string
The path to transform.

Returns

xs:anyURI
The file URI corresponding to
path
.

read-binary#1

declare  %an:nondeterministic function file:read-binary($file as xs:string) as xs:base64Binary external
Reads the content of a file and returns a Base64 representation of the content.

Parameters

file as xs:string
The file to read.

Returns

xs:base64Binary
The content of the file as Base64.

read-text-lines#1

declare  %an:nondeterministic function file:read-text-lines($file as xs:string) as xs:string*
Reads the content of a file and returns a sequence of strings representing the lines in the content of the file. The operation is equivalent to calling:
file:read-text-lines($file, "UTF-8")
.

Parameters

file as xs:string
The file to read.

Returns

xs:string*
The content of the file as a sequence of strings.

read-text-lines#2

declare  %an:nondeterministic function file:read-text-lines($file as xs:string, $encoding as xs:string) as xs:string* external
Reads the content of a file using the specified encoding and returns a sequence of strings representing the lines in the content of the file. This implementation considers the LF ( ) character as the line separator. If a resulting line ends with the CR ( ) character, this is trimmed as well. This implementation will uniformly treat LF and CRLF as line separators.

Parameters

file as xs:string
The file to read.
encoding as xs:string
The encoding used when reading the file. If compiled with ICU, then Zorba supports any encoding that ICU supports; otherwise Zorba only supports ASCII and UTF-8. The encoding parameter is case insensitive.

Returns

xs:string*
The content of the file as a sequence of strings.

read-text#1

declare  %an:nondeterministic function file:read-text($file as xs:string) as xs:string
Reads the content of a file and returns a string representation of the content. The operation is equivalent to calling:
file:read-text($file, "UTF-8")
.

Parameters

file as xs:string
The file to read.

Returns

xs:string
The content of the file as string.

read-text#2

declare  %an:nondeterministic function file:read-text($file as xs:string, $encoding as xs:string) as xs:string external
Reads the content of a file using the specified encoding and returns a string representation of the content.

Parameters

file as xs:string
The file to read.
encoding as xs:string
The encoding used when reading the file. If compiled with ICU, then Zorba supports any encoding that ICU supports; otherwise Zorba only supports ASCII and UTF-8. The encoding parameter is case insensitive.

Returns

xs:string
The content of the file as string.

resolve-path#1

declare  function file:resolve-path($path as xs:string) as xs:string external
Transforms a relative path/URI into an absolute operating system path by resolving it against the current working directory. No path existence check is made.

Parameters

path as xs:string
The path/URI to transform.

Returns

xs:string
The operating system file path.

size#1

declare  %an:nondeterministic function file:size($file as xs:string) as xs:integer external
Retrieves the size of a file.

Parameters

file as xs:string
The file get the size.

Returns

xs:integer
An integer representing the size in bytes of the file.

write-binary#2

declare  %an:sequential function file:write-binary($file as xs:string, $content as xs:base64Binary) as empty-sequence() external
Writes a sequence of Base64 items as binary to a file.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:base64Binary
The content to be written to the file.

Returns

empty-sequence()
The empty sequence.

write-text-lines#2

declare  %an:sequential function file:write-text-lines($file as xs:string, $content as xs:string*) as empty-sequence()
Writes a sequence of strings to a file, each followed by a platform-dependent newline character(s), using the UTF-8 character encoding.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.

Returns

empty-sequence()
The empty sequence.

write-text-lines#3

declare  %an:sequential function file:write-text-lines($file as xs:string, $content as xs:string*, $encoding as xs:string) as empty-sequence() external
Writes a sequence of strings to a file, each followed by a platform-dependent newline character(s).

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.
encoding as xs:string
The character encoding to write $content as.

Returns

empty-sequence()
The empty sequence.

write-text#2

declare  %an:sequential function file:write-text($file as xs:string, $content as xs:string) as empty-sequence()
Writes a sequence of strings to a file using the UTF-8 character encoding.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.

Returns

empty-sequence()
The empty sequence.

write-text#3

declare  %an:sequential function file:write-text($file as xs:string, $content as xs:string, $encoding as xs:string) as empty-sequence() external
Writes a sequence of strings to a file.

Parameters

file as xs:string
The path/URI of the file to write the content to.
content as xs:string
The content to be written to the file.
encoding as xs:string
The character encoding to write $content as.

Returns

empty-sequence()
The empty sequence.