Difference between revisions of "File Module"

From BaseX Documentation
Jump to navigation Jump to search
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 <a href="http://expath.org/spec/file">EXPath</a> specification.</p>
+
<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>
  
==file:exists==  
+
==file:exists==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:exists</b>($path as xs:string) as xs:boolean</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:exists</b>($path as xs:string) as xs:boolean</code>  
+
| Checks if a path exist.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| 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>.<br />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Checks if a path exist.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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>.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:is-directory==  
+
==file:is-directory==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:is-directory</b>($path as xs:string) as xs:boolean</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:is-directory</b>($path as xs:string) as xs:boolean</code>  
+
| Checks if a path points to a directory.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| 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 />  
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Checks if a path points to a directory.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:is-file==  
+
==file:is-file==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:is-file</b>($path as xs:string) as xs:boolean</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:is-file</b>($path as xs:string) as xs:boolean</code>  
+
| Checks if a path points to a file.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| 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 />  
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Checks if a path points to a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:is-readable==  
+
==file:is-readable==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:is-readable</b>($path as xs:string) as xs:boolean</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:is-readable</b>($path as xs:string) as xs:boolean</code>  
+
| Checks if a file is readable.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| 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 />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Checks if a file is readable.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:is-writable==  
+
==file:is-writable==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:is-writable</b>($path as xs:string) as xs:boolean</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:is-writable</b>($path as xs:string) as xs:boolean</code>  
+
| Checks if a file is writeable.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| 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 />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Checks if a file is writeable.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:last-modified==  
+
==file:last-modified==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:last-modified</b>($path as xs:string) as xs:dateTime</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:last-modified</b>($path as xs:string) as xs:dateTime</code>  
+
| Returns the timestamp of a path.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function retrieves the timestamp of the last modification of the item pointed by the path provided by the parameter<code>$path</code>.<br />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Returns the timestamp of a path.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function retrieves the timestamp of the last modification of the item pointed by the path provided by the parameter<code>$path</code>.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:files==  
+
==file:files==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<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>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:files</b>($path as xs:string) as xs:string*</code>  
+
| Lists files of a directory.
      <br />  
+
|-
      <code>  
+
| <b>Rules</b>
        <b>file:files</b>($path as xs:string, $recursive as xs:boolean) as xs:string*</code>  
+
| 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 />
      <br />  
+
|-
      <code>  
+
| <b>Errors</b>
        <b>file:files</b>($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*</code>  
+
| <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 />  
      <br />
+
|} 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Lists files of a directory.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:read==  
+
==file:read==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:read</b>($path as xs:string) as xs:string</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:read</b>($path as xs:string) as xs:string</code>  
+
| Reads a file.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| 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 />  
  <tr>
+
|-
    <td>
+
| <b>Errors</b>
      <b>Summary</b>  
+
| <b>[FOFL0017]</b> is raised if the provided encoding is not supported.<br />
    </td>
+
|}
    <td>Reads a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <b>[FOFL0017]</b> is raised if the provided encoding is not supported.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:read-binary==  
+
==file:read-binary==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:read-binary</b>($path as xs:string) as xs:base64Binary</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:read-binary</b>($path as xs:string) as xs:base64Binary</code>  
+
| Reads a binary file.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function reads the content of the file pointed by <code>$path</code> and returns it in Base64 representation.<br />
  <tr>
+
|-
    <td>
+
| <b>Errors</b>
      <b>Summary</b>  
+
| <b>[FOFL0001]</b> is raised if the file cannot be read.<br />
    </td>
+
|}
    <td>Reads a binary file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function reads the content of the file pointed by <code>$path</code> and returns it as a string.<br />This function reads the content of the file pointed by <code>$path</code> and returns it in Base64 representation.<br />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <b>[FOFL0001]</b> is raised if the file cannot be read.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:size==  
+
==file:size==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:size</b>($path as xs:string) as xs:integer</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:size</b>($path as xs:string) as xs:integer</code>  
+
| Returns the file size.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function returns the size, in bytes, of the file pointed by <code>$path</code>.<br />
  <tr>
+
|-
    <td>
+
| <b>Errors</b>
      <b>Summary</b>  
+
| <b>[FOFL0001]</b> is raised if the file cannot be read.<br />
    </td>
+
|}
    <td>Returns the file size.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function returns the size, in bytes, of the file pointed by <code>$path</code>.<br />  
 
    </td>  
 
  </tr>  
 
</table>  
 
 
   
 
   
==file:write==  
+
==file:write==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<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>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:write</b>($path as xs:string, $items as xs:item()*, $params as xs:node()*) as empty-sequence()</code>  
+
| Writes a sequence of items to a file.
      <br />  
+
|-
      <code>  
+
| <b>Rules</b>
        <b>file:write</b>($path as xs:string, $items as xs:item()*, $params as xs:node()*, $append as xs:boolean) as empty-sequence()</code>  
+
| 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 />
      <br />
+
|-
    </td>
+
| <b>Errors</b>
  </tr>
+
| <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 />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Writes a sequence of items to a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 <a href="http://www.w3.org/TR/xslt-xquery-serialization/">XSLT 2.0 and XQuery 1.0 Serialization</a>.<br />If the <code>$append</code> flag is true and the file does not exist, a new one is created.<br />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:write-binary==  
+
==file:write-binary==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<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>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:write-binary</b>($path as xs:string, $items as xs:base64Binary) as empty-sequence()</code>  
+
| Writes a sequence of items to a file.
      <br />  
+
|-
      <code>  
+
| <b>Rules</b>
        <b>file:write-binary</b>($path as xs:string, $items as xs:base64Binary, $append as xs:boolean) as empty-sequence()</code>  
+
| 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 />  
      <br />
+
|-
    </td>
+
| <b>Errors</b>
  </tr>
+
| <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 />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Writes a sequence of items to a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:mkdir==  
+
==file:mkdir==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:mkdir</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:mkdir</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code>  
+
| Creates a new directory.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function creates a directory.<br />The optional parameter <code>$recursive</code> indicates whether parent directories are to be created recursively.<br />  
  <tr>
+
|-
    <td>
+
| <b>Errors</b>
      <b>Summary</b>  
+
| <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 />
    </td>
+
|}
    <td>Creates a newwdirectory.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function creates a directory.<br />The optional parameter <code>$recursive</code> indicates whether parent directories are to be created recursively.<br />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:delete==  
+
==file:delete==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:delete</b>($path as xs:string) as empty-sequence()</code><br /><b>file:delete</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:delete</b>($path as xs:string) as empty-sequence()</code>  
+
| Deletes a file.
      <br />  
+
|-
      <code>
+
| <b>Rules</b>
        <b>file:delete</b>($path as xs:string, $recursive as xs:boolean) as empty-sequence()</code>  
+
| 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 />  
      <br />
+
|-
    </td>
+
| <b>Errors</b>
  </tr>
+
| <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 />  
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Deletes a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:copy==  
+
==file:copy==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:copy</b>($source as xs:string, $target as xs:string) as empty-sequence()</code><br /><b>file:copy</b>($source as xs:string, $target as xs:string, $overwrite as xs:boolean) as empty-sequence()</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:copy</b>($source as xs:string, $target as xs:string) as empty-sequence()</code>  
+
| Copies a file.
      <br />  
+
|-
      <code>
+
| <b>Rules</b>
        <b>file:copy</b>($source as xs:string, $target as xs:string, $overwrite as xs:boolean) as empty-sequence()</code>  
+
| 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 />  
      <br />
+
|-
    </td>
+
| <b>Errors</b>
  </tr>
+
| <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 />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Copies a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>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 />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:move==  
+
==file:move==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:move</b>($source as xs:string, $target as xs:string) as empty-sequence()</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:move</b>($source as xs:string, $target as xs:string) as empty-sequence()</code>  
+
| Moves a file.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function moves/renames the file pointed by <code>$source</code> to <code>$target</code>.<br />
  <tr>
+
|-
    <td>
+
| <b>Errors</b>
      <b>Summary</b>  
+
| <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 />  
    </td>
+
|}
    <td>Moves a file.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function moves/renames the file pointed by <code>$source</code> to <code>$target</code>.<br />  
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Errors</b>  
 
    </td>
 
    <td>
 
      <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 />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:path-separator==  
+
==file:path-separator==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:path-separator</b>() as xs:string</code>
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:path-separator</b>() as xs:string</code>  
+
| Returns the path separator.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function returns the path separator used by the operating system.<br />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Returns the path separator.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function returns the path separator used by the operating system.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:path-to-full-path==  
+
==file:path-to-full-path==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:path-to-full-path</b>($path as xs:string) as xs:string</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:path-to-full-path</b>($path as xs:string) as xs:string</code>  
+
| Returns a full path representation.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function transforms a path into a full operating system path.<br />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Returns a full path representation.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function transforms a path into a full operating system path.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
   
 
   
==file:path-to-uri==  
+
==file:path-to-uri==
<table>
+
 
  <tr>
+
{|
    <td width="90">
+
|-
      <b>Signatures</b>  
+
| width="90" | <b>Signatures</b>
    </td>
+
|<code><b>file:path-to-uri</b>($path as xs:string) as xs:string</code>  
    <td>
+
|-
      <code>  
+
| <b>Summary</b>
        <b>file:path-to-uri</b>($path as xs:string) as xs:string</code>  
+
| >Returns a URI representation.
      <br />
+
|-
    </td>
+
| <b>Rules</b>
  </tr>
+
| This function transforms a file system path into a URI with the file:// scheme.<br />
  <tr>
+
|}
    <td>
 
      <b>Summary</b>  
 
    </td>
 
    <td>Returns a URI representation.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>  
 
    </td>
 
    <td>This function transforms a file system path into a URI with the file:// scheme.<br />  
 
    </td>
 
  </tr>
 
</table>
 
 
[[Category:XQuery]]
 
[[Category:XQuery]]
[[Category:Wikify]]
 

Revision as of 17:03, 12 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 checks if a path is already used in the file system. The function returns true if the file or directory pointed by the $path parameter already exists. Otherwise it returns false.

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 checks if a path points to a directory. The function returns true if the path points to a directory. Otherwise, it returns false.

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 checks if a path points to a file. The function returns true if the path points to a file. Otherwise, it returns false.

file:is-readable

Signatures file:is-readable($path as xs:string) as xs:boolean
Summary Checks if a file is readable.
Rules This function checks if the file pointed by $path is readable. The function returns true if the file is readable. Otherwise it returns false.

file:is-writable

Signatures file:is-writable($path as xs:string) as xs:boolean
Summary Checks if a file is writeable.
Rules This function checks if the file pointed by $path is writeable. The function returns true if the file is writeable. Otherwise it returns false.

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 item pointed by the path provided by the parameter$path.

file:files

Signatures file:files($path as xs:string) as xs:string*
file:files($path as xs:string, $recursive as xs:boolean) as xs:string*
file:files($path as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*
Summary Lists files of a directory.
Rules This function lists all files in a given directory. The special files "." and ".." are never returned.
The optional parameter $recursive indicates whether the search shall recurse in the subdirectories.
The optional parameter $pattern defines a pattern and if it is present, only the files, which names match the given pattern, will be returned.
Errors [FOFL0003] is raised if files in the given directory cannot be returned.
[FOFL0004] is raised for an invalid file pattern.

file:read

Signatures file:read($path as xs:string) as xs:string
Summary Reads a file.
Rules This function reads the content of the file pointed by $path and returns it as a string.
The optional parameter $encoding defines the encoding type of the file.
Errors [FOFL0017] is raised if the provided encoding is not supported.

file:read-binary

Signatures file:read-binary($path as xs:string) as xs:base64Binary
Summary Reads a binary file.
Rules This function reads the content of the file pointed by $path and returns it in Base64 representation.
Errors [FOFL0001] is raised if the file cannot be read.

file:size

Signatures file:size($path as xs:string) as xs:integer
Summary Returns the file size.
Rules This function returns the size, in bytes, of the file pointed by $path.
Errors [FOFL0001] is raised if the file cannot be read.

file:write

Signatures 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 of items to a file. It either creates a new file, or appends the serialized content to the file pointed by $path.
The $params parameter is used to set the serialization parameters as defined in XSLT 2.0 and XQuery 1.0 Serialization.
If the $append flag is true and the file does not exist, a new one is created.
Errors [FOFL0002] is raised if the file cannot be written.
[FOFL0008] is raised if the $append flag is false and a file with the same path already exists.

file:write-binary

Signatures file:write-binary($path as xs:string, $items as xs:base64Binary) as empty-sequence()
file:write-binary($path as xs:string, $items as xs:base64Binary, $append as xs:boolean) as empty-sequence()
Summary Writes a sequence of items to a file.
Rules This function writes binary data into a file. It either creates a new file or appends the content to the file pointed by $path.
If the $append flag is true and the file does not exist, a new one is created.
Errors [FOFL0002] is raised if the file cannot be written.
[FOFL0008] is raised if the $append flag is false and a file with the same path already exists.

file:mkdir

Signatures file:mkdir($path as xs:string, $recursive as xs:boolean) as empty-sequence()
Summary Creates a new directory.
Rules This function creates a directory.
The optional parameter $recursive indicates whether parent directories are to be created recursively.
Errors [FOFL0008] is raised if a file with the same path already exists in the file system.
[FOFL0011] is raised if the directory in which the new sub-directory is to be created is write protected.
[FOFL0012] is raised if the directory cannot be created 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.
Rules This function deletes a file or directory from the file system.
If the optional parameter $recursive is provided, the operation is performed recursively for all sub-directories of the given directory.
Errors [FOFL0005] is raised if the file/directory pointed by $path is write-protected and cannot be deleted.
[FOFL0006] is raised if the file/directory pointed by $path does not exist.
[FOFL0013] is raised if the file/directory pointed by $path cannot be deleted for some other reason.

file:copy

Signatures file:copy($source as xs:string, $target as xs:string) as empty-sequence()
file:copy($source as xs:string, $target as xs:string, $overwrite as xs:boolean) as empty-sequence()
Summary Copies a file.
Rules This function copies a file specified by $source to $target.
If the optional parameter $overwrite is provided and evaluates to true, the target file, if it exists, will be overwritten.
Errors [FOFL0006] is raised if the file pointed by $source does not exist.
[FOFL0008] is raised if the file to be copied already exists in the specified target and the $overwrite parameter is missing or evaluates to false.
[FOFL0016] is raised if the source file cannot be copied because of 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/renames the file pointed by $source to $target.
Errors [FOFL0006] is raised if the file pointed by $source does not exist.
[FOFL0008] is raised if a file/directory with the same name already exists in the given target.
[FOFL0009] is raised if the item pointed by $source is a directory.
[FOFL0010] is raised if the file pointed by $source is write-protected and cannot be moved.
[FOFL0014] is raised if the file cannot be moved 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 a 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 a file system path into a URI with the file:// scheme.