http://expath.org/ns/file ZC

Module Description
Before using any of the functions below please remember to import the module namespace:
import module namespace file = "http://expath.org/ns/file";

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

Author:

Gabriel Petrovay, Matthias Brantner, Markus Pilman

XQuery version and encoding for this module:

xquery version "3.0" encoding "utf-8";

Zorba version for this module:

The latest version of this module is 2.0. For more information about module versioning in Zorba please check out this resource.

Module Resources
Module Dependencies

Imported schemas:

Please note that the schemas are not automatically imported in the modules that import this module.
In order to import and use the schemas, please add:

import schema namespace output =  "http://www.w3.org/2010/xslt-xquery-serialization";

Related Documentation

For more details please also see:

Namespaces
an http://www.zorba-xquery.com/annotations
file http://expath.org/ns/file
output http://www.w3.org/2010/xslt-xquery-serialization
ver http://www.zorba-xquery.com/options/versioning
Function Summary
Sequential append ( $file as xs:string, $content as item()*, $serializer-params as element(output:serialization-parameters)? ) as empty-sequence()
Appends a sequence of items to a file.
Sequential External append-binary ( $file as xs:string, $content as xs:base64Binary* ) as empty-sequence()
Appends a sequence of Base64 items as binary to a file.
base-name ( $path as xs:string ) as xs:string
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.
Sequential Nondeterministic 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.
Sequential External create-directory ( $dir as xs:string ) as empty-sequence()
Creates a directory.
Sequential Nondeterministic 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
This function is the converse of file:base-name.
External directory-separator ( ) as xs:string
This function returns the value of the operating system specific directory separator.
Nondeterministic External exists ( $path as xs:string ) as xs:boolean
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.
Nondeterministic External is-directory ( $dir as xs:string ) as xs:boolean
Tests if a path/URI points to a directory.
Nondeterministic External is-file ( $file as xs:string ) as xs:boolean
Tests if a path/URI points to a file.
Nondeterministic External last-modified ( $path as xs:string ) as xs:dateTime
Retrieves the timestamp of the last modification of the file system item pointed by the path/URI.
Nondeterministic External list ( $dir as xs:string ) as xs:string*
Lists the file system items in a certain directory.
Nondeterministic list ( $path as xs:string, $recursive as xs:boolean ) as xs:string*
Lists the file system items in a certain directory.
Nondeterministic 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.
Sequential 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.
External path-separator ( ) as xs:string
This function returns the value of the operating system specific path separator.
External path-to-native ( $path as xs:string ) as xs:string
Transforms a URI, an absolute path, or relative path to a native path on the running platform.
External path-to-uri ( $path as xs:string ) as xs:anyURI
Transforms a file system path into a URI with the file:// scheme.
Nondeterministic External read-binary ( $file as xs:string ) as xs:base64Binary
Reads the content of a file and returns a Base64 representation of the content.
Nondeterministic read-text ( $file as xs:string ) as xs:string
Reads the content of a file and returns a string representation of the content.
Nondeterministic External read-text ( $file as xs:string, $encoding as xs:string ) as xs:string
Reads the content of a file using the specified encoding and returns a string representation of the content.
Nondeterministic 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.
Nondeterministic External read-text-lines ( $file as xs:string, $encoding as xs:string ) as xs:string*
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.
External resolve-path ( $path as xs:string ) as xs:string
Transforms a relative path/URI into an absolute operating system path by resolving it against the current working directory.
Nondeterministic External size ( $file as xs:string ) as xs:integer
Retrieves the size of a file.
Sequential write ( $file as xs:string, $content as item()*, $serializer-params as element(output:serialization-parameters)? ) as empty-sequence()
Writes a sequence of items to a file.
Sequential External write-binary ( $file as xs:string, $content as xs:base64Binary* ) as empty-sequence()
Writes a sequence of Base64 items as binary to a file.
Sequential External write-binary ( $file as xs:string, $content as xs:base64Binary* ) as empty-sequence()
Writes a sequence of Base64 items as binary to a file.
Functions
Sequential append back to 'Function Summary'
declare function file:append (
            $file as xs:string,
            $content as item()*,
            $serializer-params as element(output:serialization-parameters)?
) as empty-sequence()

Appends a sequence of items to a file. If the file pointed by

$file
does not exist, a new file will be created. Before writing to the file, the items are serialized according to the
$serializer-params
. The semantics of
$serializer-params
is the same as for the
$params
parameter of the fn:serialize function.

Parameters:
Returns:
Errors:

Sequential External append-binary back to 'Function Summary'
declare function file:append-binary (
            $file as xs:string,
            $content as xs:base64Binary*
) as empty-sequence()

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:
Returns:
Errors:

base-name back to 'Function Summary'
declare function file:base-name (
            $path as xs:string
) as xs:string

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:
Returns:

base-name back to 'Function Summary'
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:
Returns:

Sequential copy back to 'Function Summary'
declare 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:
Returns:
Errors:

Sequential External create-directory back to 'Function Summary'
declare function file:create-directory (
            $dir as xs:string
) as empty-sequence()

Creates a directory. The operation is will create all the missing parent directories from the given path.

Parameters:
Returns:
Errors:

Sequential delete back to 'Function Summary'
declare 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:
Returns:
Errors:

dir-name back to 'Function Summary'
declare function file:dir-name (
            $path as xs:string
) as xs:string

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:
Returns:

External directory-separator back to 'Function Summary'
declare function file:directory-separator (

) as xs:string

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

/
on UNIX-based systems and
\
on Windows systems.

Returns:

Nondeterministic External exists back to 'Function Summary'
declare function file:exists (
            $path as xs:string
) as xs:boolean

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

Parameters:
Returns:

glob-to-regex back to 'Function Summary'
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:
Returns:

Nondeterministic External is-directory back to 'Function Summary'
declare function file:is-directory (
            $dir as xs:string
) as xs:boolean

Tests if a path/URI points to a directory. On UNIX-based systems, the root and the volume roots are considered directories.

Parameters:
Returns:

Nondeterministic External is-file back to 'Function Summary'
declare function file:is-file (
            $file as xs:string
) as xs:boolean

Tests if a path/URI points to a file.

Parameters:
Returns:

Nondeterministic External last-modified back to 'Function Summary'
declare function file:last-modified (
            $path as xs:string
) as xs:dateTime

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

Parameters:
Returns:
Errors:

Nondeterministic External list back to 'Function Summary'
declare function file:list (
            $dir as xs:string
) as xs:string*

Lists the file system items in a certain directory. The operation is equivalent to calling:

file:list($dir, fn:false())
.

Parameters:
Returns:
Errors:

list back to 'Function Summary'
declare 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:
Returns:
Errors:

list back to 'Function Summary'
declare 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:

Parameters:
Returns:
Errors:

Sequential move back to 'Function Summary'
declare 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:
Returns:
Errors:

External path-separator back to 'Function Summary'
declare function file:path-separator (

) as xs:string

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

:
on UNIX-based systems and
;
on Windows systems.

Returns:

External path-to-native back to 'Function Summary'
declare function file:path-to-native (
            $path as xs:string
) as xs:string

Transforms a URI, an absolute path, or relative path to a native path on the running platform. No path existence check is made.

Parameters:
Returns:
Errors:

External path-to-uri back to 'Function Summary'
declare function file:path-to-uri (
            $path as xs:string
) as xs:anyURI

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:
Returns:

Nondeterministic External read-binary back to 'Function Summary'
declare function file:read-binary (
            $file as xs:string
) as xs:base64Binary

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

Parameters:
Returns:
Errors:

read-text back to 'Function Summary'
declare 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:
Returns:
Errors:

Nondeterministic External read-text back to 'Function Summary'
declare function file:read-text (
            $file as xs:string,
            $encoding as xs:string
) as xs:string

Reads the content of a file using the specified encoding and returns a string representation of the content. In Zorba only the following encodings are currently supported: "UTF-8", "UTF8". The encoding parameter is case insensitive.

Parameters:
Returns:
Errors:

read-text-lines back to 'Function Summary'
declare 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:
Returns:
Errors:

Nondeterministic External read-text-lines back to 'Function Summary'
declare function file:read-text-lines (
            $file as xs:string,
            $encoding as xs:string
) as xs:string*

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. In Zorba only the following encodings are currently supported: "UTF-8", "UTF8". The encoding parameter is case insensitive.

Parameters:
Returns:
Errors:

External resolve-path back to 'Function Summary'
declare function file:resolve-path (
            $path as xs:string
) as xs:string

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:
Returns:

Nondeterministic External size back to 'Function Summary'
declare function file:size (
            $file as xs:string
) as xs:integer

Retrieves the size of a file.

Parameters:
Returns:
Errors:

Sequential write back to 'Function Summary'
declare function file:write (
            $file as xs:string,
            $content as item()*,
            $serializer-params as element(output:serialization-parameters)?
) as empty-sequence()

Writes a sequence of items to a file. Before writing to the file, the items are serialized according to the

$serializer-params
. The semantics of
$serializer-params
is the same as for the
$params
parameter of the fn:serialize function.

Parameters:
Returns:
Errors:

Sequential External write-binary back to 'Function Summary'
declare function file:write-binary (
            $file as xs:string,
            $content as xs:base64Binary*
) as empty-sequence()

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

Parameters:
Returns:
Errors:

Sequential External write-binary back to 'Function Summary'
declare function file:write-binary (
            $file as xs:string,
            $content as xs:base64Binary*
) as empty-sequence()

Writes a sequence of Base64 items as binary to a file. The operation is equivalent to calling:

file:write-binary($file, $content, fn:true())
.

Parameters:
Returns:
Errors:

blog comments powered by Disqus