Difference between revisions of "File Module"

From BaseX Documentation
Jump to navigation Jump to search
m (moved File to File Functions: consistent naming)
(based on docs2wiki.xq)
Line 1: Line 1:
<p>The file module contains extension functions to perform file system related operations, such as listing, reading, or writing files. All functions are preceded by the <code>file:</code> prefix. Some changes might happen to this module, as it is currently aligned with the upcoming [http://expath.org/spec/file EXPath] specification.</p>
+
The file module contains extension functions to perform file system related operations, such as listing, reading, or writing files. All functions are preceded by the <code>file:</code> prefix. Some changes might happen to this module, as it is currently aligned with the upcoming [http://expath.org/spec/file EXPath] specification.
  
 
==file:exists==
 
==file:exists==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | '''Signatures'''
+
| valign='top' width='90' | '''Signatures'''
|<code>'''file:exists'''($path as xs:string) as xs:boolean</code>
+
|<code><b>file:exists</b>($path as xs:string) as xs:boolean</code><br />
 
|-
 
|-
| '''Summary'''
+
| valign='top' | '''Summary'''
| Checks if a path exist.
+
|Checks if a path exist.
 
|-
 
|-
| '''Rules'''
+
| valign='top' | '''Rules'''
| This function checks if a path is already used in the file system. The function returns <code>true</code> if the file or directory pointed by the <code>$path</code> parameter already exists. Otherwise it returns <code>false</code>.
+
|This function returns an <code>xs:boolean</code> indicating whether a file or directory specified by <code>$path</code> exists in the file system.<br />
 
|}
 
|}
  
 
==file:is-directory==
 
==file:is-directory==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:is-directory</b>($path as xs:string) as xs:boolean</code>
+
|<code><b>file:is-directory</b>($path as xs:string) as xs:boolean</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Checks if a path points to a directory.
+
|Checks if a path points to a directory.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function checks if a path points to a directory. The function returns <code>true</code> if the path points to a directory. Otherwise, it returns <code>false</code>.<br />  
+
|This function returns an <code>xs:boolean</code> indicating whether the argument <code>$path</code> points to an existing directory.<br />
 
|}
 
|}
+
 
 
==file:is-file==
 
==file:is-file==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:is-file</b>($path as xs:string) as xs:boolean</code>
+
|<code><b>file:is-file</b>($path as xs:string) as xs:boolean</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Checks if a path points to a file.
+
|Checks if a path points to a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function checks if a path points to a file. The function returns <code>true</code> if the path points to a file. Otherwise, it returns <code>false</code>.<br />  
+
|This function returns an <code>xs:boolean</code> indicating whether the argument <code>$path</code> points to an existing file.<br />
|}  
+
|}
+
 
 
==file:is-readable==
 
==file:is-readable==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:is-readable</b>($path as xs:string) as xs:boolean</code>
+
|<code><b>file:is-readable</b>($path as xs:string) as xs:boolean</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Checks if a file is readable.
+
|Checks if a file is readable.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function checks if the file pointed by <code>$path</code> is readable. The function returns <code>true</code> if the file is readable. Otherwise it returns <code>false</code>.<br />
+
|This function returns an <code>xs:boolean</code> indicating whether the file specified by <code>$path</code> exists and is readable.<br />
 
|}
 
|}
+
 
 
==file:is-writable==
 
==file:is-writable==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:is-writable</b>($path as xs:string) as xs:boolean</code>
+
|<code><b>file:is-writable</b>($path as xs:string) as xs:boolean</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Checks if a file is writeable.
+
|Checks if a file is writable.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function checks if the file pointed by <code>$path</code> is writeable. The function returns <code>true</code> if the file is writeable. Otherwise it returns <code>false</code>.<br />
+
|This function returns an <code>xs:boolean</code> indicating whether the file specified by <code>$path</code> exists and is writable.<br />
 
|}
 
|}
+
 
 
==file:last-modified==
 
==file:last-modified==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:last-modified</b>($path as xs:string) as xs:dateTime</code>
+
|<code><b>file:last-modified</b>($path as xs:string) as xs:dateTime</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Returns the timestamp of a path.
+
|Returns the timestamp of a path.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function retrieves the timestamp of the last modification of the item pointed by the path provided by the parameter<code>$path</code>.<br />
+
|This function retrieves the timestamp of the last modification of the file or directory specified by <code>$path</code>.<br />
|}
+
|-
+
| valign='top' | '''Errors'''
==file:files==
+
|<b>[FOFL0001]</b> is raised if the specified path does not exist.<br />
 +
|}
  
 +
==file:size==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:files</b>($path as xs:string) as xs:string*</code> <br /> <code><b>file:files</b>($path as xs:string, $recursive as xs:boolean) as xs:string*</code> <br /> <code><b>file:files</b>($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*</code>
+
|<code><b>file:size</b>($path as xs:string) as xs:integer</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Lists files of a directory.
+
|Returns the size of a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function lists all files in a given directory. The special files "." and ".." are never returned.<br />The optional parameter <code>$recursive</code> indicates whether the search shall recurse in the subdirectories.<br />The optional parameter <code>$pattern</code> defines a pattern and if it is present, only the files, which names match the given pattern, will be returned.<br />
+
|This function returns the size, in bytes, of the file specified by <code>$path</code>. The return value is unspecified if the argument points to a directory.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0003]</b> is raised if files in the given directory cannot be returned.<br /> <b>[FOFL0004]</b> is raised for an invalid file pattern.<br />  
+
|<b>[FOFL0001]</b> is raised if the specified path does not exist.<br />
|}
+
|}
 
==file:read==
 
  
 +
==file:list==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:read</b>($path as xs:string) as xs:string</code>
+
|<code><b>file:list</b>($path as xs:string) as xs:string*</code><br /><code><b>file:list</b>($path as xs:string, $recursive as xs:boolean) as xs:string*</code><br /><code><b>file:list</b>($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Reads a file.
+
|Lists the contents of a directory.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function reads the content of the file pointed by <code>$path</code> and returns it as a string.<br />The optional parameter <code>$encoding</code> defines the encoding type of the file.<br />  
+
|This function lists all files and directories found in the directory that is specified by <code>$path</code>. The returned paths are relative to the provided path.<br />The optional parameter <code>$recursive</code> specifies whether the sub-directories are to be recursed as well.<br />The optional parameter <code>$pattern</code> defines a file name pattern. If present, only those files and directories are returned that correspond to the pattern. A pattern may contain asterisks (<code>*</code>) to match zero or more characters, and question marks (<code>?</code>) to match single characters. Several patterns can be separated with a comma (<code>,</code>).<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0017]</b> is raised if the provided encoding is not supported.<br />
+
|<b>[FOFL0001]</b> is raised if the specified path does not exist.<br /><b>[FOFL0003]</b> is raised if the specified path does not point to a directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
|}  
+
|}
 
==file:read-binary==
 
  
 +
==file:create-directory==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:read-binary</b>($path as xs:string) as xs:base64Binary</code>
+
|<code><b>file:create-directory</b>($path as xs:string) as empty-sequence()</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Reads a binary file.
+
|Creates a new directory path.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function reads the content of the file pointed by <code>$path</code> and returns it in Base64 representation.<br />
+
|This function recursively creates the directories specified by <code>$path</code>.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0001]</b> is raised if the file cannot be read.<br />
+
|<b>[FOFL0002]</b> is raised if a file with the same path already exists.<br /><b>[FOFL0006]</b> is raised if the specified path is invalid (e.g., contains invalid characters).<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
 
==file:size==
 
  
 +
==file:delete==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:size</b>($path as xs:string) as xs:integer</code>  
+
|<code><b>file:delete</b>($path as xs:string) as empty-sequence()</code><br /><code><b>file:delete</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Returns the file size.
+
|Deletes a file or directory.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function returns the size, in bytes, of the file pointed by <code>$path</code>.<br />
+
|This function deletes a file or directory specified by <code>$path</code>. No operation will be performed if the specified path does not exist.<br />If the optional parameter <code>$recursive</code> is provided, the operation is performed recursively for all sub-directories of the given path.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0001]</b> is raised if the file cannot be read.<br />
+
|<b>[FOFL0005]</b> is raised if <code>$recursive</code> is not specified or set to <code>false</code>, and if the specified path points to a non-empty directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
 
==file:write==
 
  
 +
==file:read==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:write</b>($path as xs:string, $items as xs:item()*, $params as xs:node()*) as empty-sequence()</code> <br /><code><b>file:write</b>($path as xs:string, $items as xs:item()*, $params as xs:node()*, $append as xs:boolean) as empty-sequence()</code>
+
|<code><b>file:read</b>($path as xs:string) as xs:string</code><br /><code><b>file:read</b>($path as xs:string, $encoding as xs:string) as xs:string</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Writes a sequence of items to a file.
+
|Reads the contents a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function writes a sequence of <code>items</code> to a file. It either creates a new file, or appends the serialized content to the file pointed by <code>$path</code>.<br />The <code>$params</code> parameter is used to set the serialization parameters as defined in [http://www.w3.org/TR/xslt-xquery-serialization XSLT 2.0 and XQuery 1.0 Serialization].<br />If the <code>$append</code> flag is true and the file does not exist, a new one is created.<br />
+
|This function reads the textual contents of the file specified by <code>$path</code> and returns it as a <code>xs:string</code>.<br />The optional parameter <code>$encoding</code> defines the encoding of the file.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0002]</b> is raised if the file cannot be written.<br /><b>[FOFL0008]</b> is raised if the <code>$append</code> flag is <code>false</code> and a file  with the same path already exists.<br />
+
|<b>[FOFL0001]</b> is raised if the specified file does not exist.<br /><b>[FOFL0004]</b> is raised if the specified path is a directory.<br /><b>[FOFL0007]</b> is raised if the specified encoding is not supported, or unknown.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
 
==file:write-binary==
 
  
 +
==file:read-binary==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:write-binary</b>($path as xs:string, $items as xs:base64Binary) as empty-sequence()</code> <br /><code><b>file:write-binary</b>($path as xs:string, $items as xs:base64Binary, $append as xs:boolean) as empty-sequence()</code>  
+
|<code><b>file:read-binary</b>($path as xs:string) as xs:base64Binary</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Writes a sequence of items to a file.
+
|Reads the binary contents of a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function writes binary data into a file. It either creates a new file or appends the content to the file pointed by <code>$path</code>.<br />If the <code>$append</code> flag is true and the file does not exist, a new one is created.<br />  
+
|This function reads the binary content of the file specified by <code>$path</code> and returns as a <code>xs:base64Binary</code>.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0002]</b> is raised if the file cannot be written.<br /><b>[FOFL0008]</b> is raised if the <code>$append</code> flag is <code>false</code> and a file  with the same path already exists.<br />
+
|<b>[FOFL0001]</b> is raised if the specified file does not exist.<br /><b>[FOFL0004]</b> is raised if the specified path is a directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
 
==file:mkdir==
 
  
 +
==file:write==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:mkdir</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code>  
+
|<code><b>file:write</b>($path as xs:string, $items as xs:item()*) as empty-sequence()</code><br /><code><b>file:write</b>($path as xs:string, $items as xs:item()*, $params as xs:node()*) as empty-sequence()</code><br /><code><b>file:write</b>($path as xs:string, $items as xs:item()*, $params as xs:node()*, $append as xs:boolean) as empty-sequence()</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Creates a new directory.
+
|Writes a sequence of items to a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function creates a directory.<br />The optional parameter <code>$recursive</code> indicates whether parent directories are to be created recursively.<br />  
+
|This function writes a sequence, specified by <code>$items</code>, to a file specified by <code>$path</code>. If the specified file already exists, it will be overwritten.<br />The optional argument <code>$params</code> is used to set the serialization parameters, as defined in [http://www.w3.org/TR/xslt-xquery-serialization/ XSLT 2.0 and XQuery 1.0 Serialization].<br />If the <code>$append</code> flag is set to <code>true</code>, the serialized items are appended to the original file. If the file does not exist, a new one is created.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0008]</b> is raised if a file with the same path already exists in the file system.<br /><b>[FOFL0011]</b> is raised if the directory in which the new sub-directory is to be created is write protected.<br /> <b>[FOFL0012]</b> is raised if the directory cannot be created for some other reason.<br />
+
|<b>[FOFL0004]</b> is raised if the specified path is a directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
 
==file:delete==
 
  
 +
==file:write-binary==
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:delete</b>($path as xs:string) as empty-sequence()</code><br /><code><b>file:delete</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code>  
+
|<code><b>file:write-binary</b>($path as xs:string, $item as xs:base64Binary) as empty-sequence()</code><br /><code><b>file:write-binary</b>($path as xs:string, $item as xs:base64Binary, $append as xs:boolean) as empty-sequence()</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Deletes a file.
+
|Writes a sequence of items to a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function deletes a file or directory from the file system.<br />If the optional parameter <code>$recursive</code> is provided, the operation is performed recursively for all sub-directories of the given directory.<br />  
+
|This function writes a <code>xs:basex64Binary</code> item specified by <code>$item</code> to a file specified by <code>$path</code>. If the specified file already exists, it will be overwritten.<br />If the <code>$append</code> flag is set to <code>true</code>, the serialized item is appended to the original file. If the file does not exist, a new one is created.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0005]</b> is raised if the file/directory pointed by <code>$path</code> is write-protected and cannot be deleted.<br /> <b>[FOFL0006]</b> is raised if the file/directory pointed by <code>$path</code> does not exist.<br /> <b>[FOFL0013]</b> is raised if the file/directory pointed by <code>$path</code> cannot be deleted for some other reason.<br />  
+
|<b>[FOFL0004]</b> is raised if the specified path is a directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
  
 
==file:copy==
 
==file:copy==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:copy</b>($source as xs:string, $target as xs:string) as empty-sequence()</code><br /><code><b>file:copy</b>($source as xs:string, $target as xs:string, $overwrite as xs:boolean) as empty-sequence()</code>  
+
|<code><b>file:copy</b>($source as xs:string, $target as xs:string) as empty-sequence()</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Copies a file.
+
|Copies a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function copies a file specified by <code>$source</code> to <code>$target</code>.<br />If the optional parameter <code>$overwrite</code> is provided and evaluates to <code>true</code>, the target file, if it exists, will be overwritten.<br />  
+
|This function copies a file specified by <code>$source</code> to the file or directory specified by <code>$target</code>. If the target represents an existing file, it will be overwritten. No operation will be performed if the source and target path are equal.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0006]</b> is raised if the file pointed by <code>$source</code> does not exist.<br /> <b>[FOFL0008]</b> is raised if the file to be copied already exists in the specified target and the <code>$overwrite</code> parameter is missing or evaluates to <code>false</code>.<br /> <b>[FOFL0016]</b> is raised if the source file cannot be copied because of some other reason.<br />
+
|<b>[FOFL0001]</b> is raised if the specified source does not exist.<br /><b>[FOFL0004]</b> is raised if the specified source is a directory.<br /><b>[FOFL0006]</b> is raised if the specified target path points to a file in a non-existing directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
 
|}
 
|}
  
 
==file:move==
 
==file:move==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:move</b>($source as xs:string, $target as xs:string) as empty-sequence()</code>  
+
|<code><b>file:move</b>($source as xs:string, $target as xs:string) as empty-sequence()</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Moves a file.
+
|Moves a file.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function moves/renames the file pointed by <code>$source</code> to <code>$target</code>.<br />
+
|This function moves, or renames, the file or directory specified by <code>$source</code> to the path specified by <code>$target</code>. No operation will be performed if the source and target path are equal.<br />
 
|-
 
|-
| <b>Errors</b>
+
| valign='top' | '''Errors'''
| <b>[FOFL0006]</b> is raised if the file pointed by <code>$source</code> does not exist.<br /> <b>[FOFL0008]</b> is raised if a file/directory with the same name already exists in the given target.<br /> <b>[FOFL0009]</b> is raised if the item pointed by <code>$source</code> is a directory.<br /> <b>[FOFL0010]</b> is raised if the file pointed by <code>$source</code> is write-protected and cannot be moved.<br /> <b>[FOFL0014]</b> is raised if the file cannot be moved for some other reason.<br />  
+
|<b>[FOFL0001]</b> is raised if the specified source does not exist.<br /><b>[FOFL0006]</b> is raised if the specified target path points to a file in a non-existing directory.<br /><b>[FOFL0008]</b> is raised if the operation fails for some other reason.<br />
|}  
+
|}
+
 
 
==file:path-separator==
 
==file:path-separator==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:path-separator</b>() as xs:string</code>
+
|<code><b>file:path-separator</b>() as xs:string</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Returns the path separator.
+
|Returns the path separator.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function returns the path separator used by the operating system.<br />
+
|This function returns the path separator used by the operating system.<br />
|}  
+
|}
+
 
 
==file:path-to-full-path==
 
==file:path-to-full-path==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:path-to-full-path</b>($path as xs:string) as xs:string</code>  
+
|<code><b>file:path-to-full-path</b>($path as xs:string) as xs:string</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Returns a full path representation.
+
|Returns a full path representation.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function transforms a path into a full operating system path.<br />
+
|This function transforms the path specified by <code>$path</code> into a full operating system path.<br />
|}  
+
|}
+
 
 
==file:path-to-uri==
 
==file:path-to-uri==
 
 
{|
 
{|
 
|-
 
|-
| width="90" | <b>Signatures</b>
+
| valign='top' width='90' | '''Signatures'''
|<code><b>file:path-to-uri</b>($path as xs:string) as xs:string</code>  
+
|<code><b>file:path-to-uri</b>($path as xs:string) as xs:string</code><br />
 
|-
 
|-
| <b>Summary</b>
+
| valign='top' | '''Summary'''
| Returns an URI representation.
+
|Returns a URI representation.
 
|-
 
|-
| <b>Rules</b>
+
| valign='top' | '''Rules'''
| This function transforms a file system path into an URI with the file:// scheme.<br />
+
|This function transforms the path specified by <code>$path</code> into a URI with the <code>file://</code> scheme.<br />
 
|}
 
|}
 +
 
[[Category:XQuery]]
 
[[Category:XQuery]]

Revision as of 20:57, 13 December 2010

The file module contains extension functions to perform file system related operations, such as listing, reading, or writing files. All functions are preceded by the file: prefix. Some changes might happen to this module, as it is currently aligned with the upcoming EXPath specification.

file:exists

Signatures file:exists($path as xs:string) as xs:boolean
Summary Checks if a path exist.
Rules This function returns an xs:boolean indicating whether a file or directory specified by $path exists in the file system.

file:is-directory

Signatures file:is-directory($path as xs:string) as xs:boolean
Summary Checks if a path points to a directory.
Rules This function returns an xs:boolean indicating whether the argument $path points to an existing directory.

file:is-file

Signatures file:is-file($path as xs:string) as xs:boolean
Summary Checks if a path points to a file.
Rules This function returns an xs:boolean indicating whether the argument $path points to an existing file.

file:is-readable

Signatures file:is-readable($path as xs:string) as xs:boolean
Summary Checks if a file is readable.
Rules This function returns an xs:boolean indicating whether the file specified by $path exists and is readable.

file:is-writable

Signatures file:is-writable($path as xs:string) as xs:boolean
Summary Checks if a file is writable.
Rules This function returns an xs:boolean indicating whether the file specified by $path exists and is writable.

file:last-modified

Signatures file:last-modified($path as xs:string) as xs:dateTime
Summary Returns the timestamp of a path.
Rules This function retrieves the timestamp of the last modification of the file or directory specified by $path.
Errors [FOFL0001] is raised if the specified path does not exist.

file:size

Signatures file:size($path as xs:string) as xs:integer
Summary Returns the size of a file.
Rules This function returns the size, in bytes, of the file specified by $path. The return value is unspecified if the argument points to a directory.
Errors [FOFL0001] is raised if the specified path does not exist.

file:list

Signatures file:list($path as xs:string) as xs:string*
file:list($path as xs:string, $recursive as xs:boolean) as xs:string*
file:list($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*
Summary Lists the contents of a directory.
Rules This function lists all files and directories found in the directory that is specified by $path. The returned paths are relative to the provided path.
The optional parameter $recursive specifies whether the sub-directories are to be recursed as well.
The optional parameter $pattern defines a file name pattern. If present, only those files and directories are returned that correspond to the pattern. A pattern may contain asterisks (*) to match zero or more characters, and question marks (?) to match single characters. Several patterns can be separated with a comma (,).
Errors [FOFL0001] is raised if the specified path does not exist.
[FOFL0003] is raised if the specified path does not point to a directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:create-directory

Signatures file:create-directory($path as xs:string) as empty-sequence()
Summary Creates a new directory path.
Rules This function recursively creates the directories specified by $path.
Errors [FOFL0002] is raised if a file with the same path already exists.
[FOFL0006] is raised if the specified path is invalid (e.g., contains invalid characters).
[FOFL0008] is raised if the operation fails for some other reason.

file:delete

Signatures file:delete($path as xs:string) as empty-sequence()
file:delete($path as xs:string, $recursive as xs:boolean) as empty-sequence()
Summary Deletes a file or directory.
Rules This function deletes a file or directory specified by $path. No operation will be performed if the specified path does not exist.
If the optional parameter $recursive is provided, the operation is performed recursively for all sub-directories of the given path.
Errors [FOFL0005] is raised if $recursive is not specified or set to false, and if the specified path points to a non-empty directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:read

Signatures file:read($path as xs:string) as xs:string
file:read($path as xs:string, $encoding as xs:string) as xs:string
Summary Reads the contents a file.
Rules This function reads the textual contents of the file specified by $path and returns it as a xs:string.
The optional parameter $encoding defines the encoding of the file.
Errors [FOFL0001] is raised if the specified file does not exist.
[FOFL0004] is raised if the specified path is a directory.
[FOFL0007] is raised if the specified encoding is not supported, or unknown.
[FOFL0008] is raised if the operation fails for some other reason.

file:read-binary

Signatures file:read-binary($path as xs:string) as xs:base64Binary
Summary Reads the binary contents of a file.
Rules This function reads the binary content of the file specified by $path and returns as a xs:base64Binary.
Errors [FOFL0001] is raised if the specified file does not exist.
[FOFL0004] is raised if the specified path is a directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:write

Signatures file:write($path as xs:string, $items as xs:item()*) as empty-sequence()
file:write($path as xs:string, $items as xs:item()*, $params as xs:node()*) as empty-sequence()
file:write($path as xs:string, $items as xs:item()*, $params as xs:node()*, $append as xs:boolean) as empty-sequence()
Summary Writes a sequence of items to a file.
Rules This function writes a sequence, specified by $items, to a file specified by $path. If the specified file already exists, it will be overwritten.
The optional argument $params is used to set the serialization parameters, as defined in XSLT 2.0 and XQuery 1.0 Serialization.
If the $append flag is set to true, the serialized items are appended to the original file. If the file does not exist, a new one is created.
Errors [FOFL0004] is raised if the specified path is a directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:write-binary

Signatures file:write-binary($path as xs:string, $item as xs:base64Binary) as empty-sequence()
file:write-binary($path as xs:string, $item as xs:base64Binary, $append as xs:boolean) as empty-sequence()
Summary Writes a sequence of items to a file.
Rules This function writes a xs:basex64Binary item specified by $item to a file specified by $path. If the specified file already exists, it will be overwritten.
If the $append flag is set to true, the serialized item is appended to the original file. If the file does not exist, a new one is created.
Errors [FOFL0004] is raised if the specified path is a directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:copy

Signatures file:copy($source as xs:string, $target as xs:string) as empty-sequence()
Summary Copies a file.
Rules This function copies a file specified by $source to the file or directory specified by $target. If the target represents an existing file, it will be overwritten. No operation will be performed if the source and target path are equal.
Errors [FOFL0001] is raised if the specified source does not exist.
[FOFL0004] is raised if the specified source is a directory.
[FOFL0006] is raised if the specified target path points to a file in a non-existing directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:move

Signatures file:move($source as xs:string, $target as xs:string) as empty-sequence()
Summary Moves a file.
Rules This function moves, or renames, the file or directory specified by $source to the path specified by $target. No operation will be performed if the source and target path are equal.
Errors [FOFL0001] is raised if the specified source does not exist.
[FOFL0006] is raised if the specified target path points to a file in a non-existing directory.
[FOFL0008] is raised if the operation fails for some other reason.

file:path-separator

Signatures file:path-separator() as xs:string
Summary Returns the path separator.
Rules This function returns the path separator used by the operating system.

file:path-to-full-path

Signatures file:path-to-full-path($path as xs:string) as xs:string
Summary Returns a full path representation.
Rules This function transforms the path specified by $path into a full operating system path.

file:path-to-uri

Signatures file:path-to-uri($path as xs:string) as xs:string
Summary Returns a URI representation.
Rules This function transforms the path specified by $path into a URI with the file:// scheme.