XQuery Function Documentation

Search and Browse

http://exist-db.org/xquery/file

java:org.exist.xquery.modules.file.FileModule

A module for performing various operations on files and directories stored in the server file system.

file:delete

file:delete($path as item()) as xs:boolean

Delete a file or directory. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the file
Returns:
xs:boolean : true if successful, false otherwise

file:directory-list

file:directory-list($path as item(), $pattern as xs:string*) as node()?

List all files, including their file size and modification time, found in or below a directory, $directory. Files are located in the server's file system, using filename patterns, $pattern. File pattern matching is based on code from Apache's Ant, thus following the same conventions. For example:
'*.xml' matches any file ending with .xml in the current directory, - '**/*.xml' matches files in any directory below the specified directory. This method is only available to the DBA role.

Parameters:
$path The base directory path or URI in the file system where the files are located.
$pattern* The file name pattern
Returns:
node()? : a node fragment that shows all matching filenames, including their file size and modification time, and the subdirectory they were found in

file:exists

file:exists($path as item()) as xs:boolean

Tests if a file or directory exists. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the file in the file system
Returns:
xs:boolean : the boolean value true if the file exists, false otherwise

file:is-directory

file:is-directory($path as item()) as xs:boolean

Tests if a path is a directory. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the file or directory
Returns:
xs:boolean : true if the path is a directory

file:is-readable

file:is-readable($path as item()) as xs:boolean

Tests if a file is readable. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the file
Returns:
xs:boolean : true if file can be read

file:is-writeable

file:is-writeable($path as item()) as xs:boolean

Tests if a file is writeable. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the file
Returns:
xs:boolean : true if the file has write permissions

file:list

file:list($path as item()) as node()*

List all files and directories under the specified directory. This method is only available to the DBA role.

Parameters:
$path The directory path or URI in the file system.
Returns:
node()* : a node describing file and directory names and meta data.

file:mkdir

file:mkdir($path as item()) as xs:boolean

Create a directory. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the directory
Returns:
xs:boolean : true if successful, false otherwise

file:mkdirs

file:mkdirs($path as item()) as xs:boolean

Create a directory including any necessary but nonexistent parent directories. This method is only available to the DBA role.

Parameters:
$path The full path or URI to the directory
Returns:
xs:boolean : true if successful, false otherwise

file:move

file:move($original as item(), $destination as item()) as xs:boolean

Move (rename) a file or directory. Exact operation is platform dependent. This method is only available to the DBA role.

Parameters:
$original The full path or URI to the file
$destination The full path or URI to the file
Returns:
xs:boolean : true if successful, false otherwise

file:read

file:read($path as item()) as xs:string?

Reads the content of file. This method is only available to the DBA role.

Parameters:
$path The directory path or URI in the file system.
Returns:
xs:string? : the file contents

file:read

file:read($path as item(), $encoding as xs:string) as xs:string?

Reads the content of file. This method is only available to the DBA role.

Parameters:
$path The directory path or URI in the file system.
$encoding The encoding type for the file
Returns:
xs:string? : the file contents

file:read-binary

file:read-binary($path as item()) as xs:base64Binary?

Reads the contents of a binary file. This method is only available to the DBA role.

Parameters:
$path The directory path or URI in the file system.
Returns:
xs:base64Binary? : the file contents

file:read-unicode

file:read-unicode($path as item()) as xs:string?

Reads the contents of a file. Unicode BOM (Byte Order Marker) will be stripped off if found. This method is only available to the DBA role.

Parameters:
$path The directory path or URI in the file system.
Returns:
xs:string? : the contents of the file

file:read-unicode

file:read-unicode($path as item(), $encoding as xs:string) as xs:string?

Reads the contents of a file. Unicode BOM (Byte Order Marker) will be stripped off if found. This method is only available to the DBA role.

Parameters:
$path The directory path or URI in the file system.
$encoding The file is read with the encoding specified.
Returns:
xs:string? : the contents of the file

file:serialize

file:serialize($node-set as node()*, $path as item(), $parameters as item()*) as xs:boolean?

Writes the node set into a file on the file system. $parameters contains a sequence of zero or more serialization parameters specified as key=value pairs. The serialization options are the same as those recognized by "declare option exist:serialize". The function does NOT automatically inherit the serialization options of the XQuery it is called from. This method is only available to the DBA role.

Parameters:
$node-set* The contents to write to the file system.
$path The full path or URI to the file
$parameters* The serialization parameters: either a sequence of key=value pairs or an output:serialization-parameters element as defined by the standard fn:serialize function.
Returns:
xs:boolean? : true on success - false if the specified file can not be created or is not writable. The empty sequence is returned if the argument sequence is empty.

file:serialize

file:serialize($node-set as node()*, $path as item(), $parameters as item()*, $append as xs:boolean) as xs:boolean?

Writes the node set into a file on the file system, optionally appending to it. $parameters contains a sequence of zero or more serialization parameters specified as key=value pairs. The serialization options are the same as those recognized by "declare option exist:serialize". The function does NOT automatically inherit the serialization options of the XQuery it is called from. This method is only available to the DBA role.

Parameters:
$node-set* The contents to write to the file system.
$path The full path or URI to the file
$parameters* The serialization parameters: either a sequence of key=value pairs or an output:serialization-parameters element as defined by the standard fn:serialize function.
$append Should content be appended?
Returns:
xs:boolean? : true on success - false if the specified file can not be created or is not writable. The empty sequence is returned if the argument sequence is empty.

file:serialize-binary

file:serialize-binary($binarydata as xs:base64Binary, $path as item()) as xs:boolean

Writes binary data into a file on the file system. This method is only available to the DBA role.

Parameters:
$binarydata The contents to write to the file system.
$path The full path or URI to the file
Returns:
xs:boolean : true on success - false if the specified file can not be created or is not writable

file:serialize-binary

file:serialize-binary($binarydata as xs:base64Binary, $path as item(), $append as xs:boolean) as xs:boolean

Writes binary data into a file on the file system, optionally appending the content. This method is only available to the DBA role.

Parameters:
$binarydata The contents to write to the file system.
$path The full path or URI to the file
$append Should content be appended?
Returns:
xs:boolean : true on success - false if the specified file can not be created or is not writable

file:sync

file:sync($collection as xs:string, $targetPath as item(), $dateTime as xs:dateTime?) as xs:boolean

Synchronize a collection with a directory hierarchy. Compares last modified time stamps. If $dateTime is given, only resources modified after this time stamp are taken into account. This method is only available to the DBA role.

Parameters:
$collection The collection to sync.
$targetPath The full path or URI to the directory
$dateTime? Optional: only resources modified after the given date/time will be synchronized.
Returns:
xs:boolean : true if successful, false otherwise