Difference between revisions of "File Module"
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This variable returns the directory separator used by the operating system, such as "/" or "\".<br /> | |This variable returns the directory separator used by the operating system, such as "/" or "\".<br /> | ||
|} | |} | ||
Line 22: | Line 19: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This variable returns the path separator used by the operating system, such as ";" or ":".<br /> | |This variable returns the path separator used by the operating system, such as ";" or ":".<br /> | ||
|} | |} | ||
Line 35: | Line 29: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|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 /> | |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 /> | ||
|} | |} | ||
Line 48: | Line 39: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function returns an <code>xs:boolean</code> indicating whether the argument <code>$path</code> points to an existing directory.<br /> | |This function returns an <code>xs:boolean</code> indicating whether the argument <code>$path</code> points to an existing directory.<br /> | ||
|} | |} | ||
Line 61: | Line 49: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function returns an <code>xs:boolean</code> indicating whether the argument <code>$path</code> points to an existing file.<br /> | |This function returns an <code>xs:boolean</code> indicating whether the argument <code>$path</code> points to an existing file.<br /> | ||
|} | |} | ||
Line 74: | Line 59: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function retrieves the timestamp of the last modification of the file or directory specified by <code>$path</code>.<br /> | |This function retrieves the timestamp of the last modification of the file or directory specified by <code>$path</code>.<br /> | ||
|- | |- | ||
Line 90: | Line 72: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function returns the size, in bytes, of the file specified by <code>$path</code>.<br /> | |This function returns the size, in bytes, of the file specified by <code>$path</code>.<br /> | ||
|- | |- | ||
Line 106: | Line 85: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function returns the base-name of the path specified by <code>$path</code>, which is the component after the last directory separator.<br /> If <code>$suffix</code> is specified, it will be trimmed from the end of the result.<br /> | |This function returns the base-name of the path specified by <code>$path</code>, which is the component after the last directory separator.<br /> If <code>$suffix</code> is specified, it will be trimmed from the end of the result.<br /> | ||
|} | |} | ||
Line 119: | Line 95: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function returns the parent directory of the path specified by <code>$path</code>, which is the component before the last directory separator.<br /> | |This function returns the parent directory of the path specified by <code>$path</code>, which is the component before the last directory separator.<br /> | ||
|} | |} | ||
Line 132: | Line 105: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function transforms the <code>$path</code> argument to its native representation on the operating system.<br /> | |This function transforms the <code>$path</code> argument to its native representation on the operating system.<br /> | ||
|- | |- | ||
Line 148: | Line 118: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function transforms the <code>$path</code> argument to an absolute operating system path.<br /> | |This function transforms the <code>$path</code> argument to an absolute operating system path.<br /> | ||
|} | |} | ||
Line 161: | Line 128: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function transforms the path specified by <code>$path</code> into a URI with the <code>file://</code> scheme.<br /> | |This function transforms the path specified by <code>$path</code> into a URI with the <code>file://</code> scheme.<br /> | ||
|} | |} | ||
Line 171: | Line 135: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>file:list</b>($ | + | |<code><b>file:list</b>($directory as xs:string) as xs:string*</code><br /><code><b>file:list</b>($directory as xs:string, $recursive as xs:boolean) as xs:string*</code><br /><code><b>file:list</b>($directory as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string*</code><br /> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | + | |This function lists all files and directories found in the specified <code>$directory</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 in the [http://en.wikipedia.org/wiki/Glob_(programming) glob syntax]. If present, only those files and directories are returned that correspond to the pattern. Several patterns can be separated with a comma (<code>,</code>).<br /> | |
− | |||
− | |||
− | |This function lists all files and directories found in the | ||
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 190: | Line 151: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function recursively creates the directories specified by <code>$path</code>.<br /> | |This function recursively creates the directories specified by <code>$path</code>.<br /> | ||
|- | |- | ||
Line 206: | Line 164: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function recursively deletes a file or directory specified by <code>$path</code>.<br /> | |This function recursively deletes a file or directory specified by <code>$path</code>.<br /> | ||
|- | |- | ||
Line 222: | Line 177: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|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 /> | |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 /> | ||
|- | |- | ||
Line 238: | Line 190: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|This function reads the binary content of the file specified by <code>$path</code> and returns as a <code>xs:base64Binary</code>.<br /> | |This function reads the binary content of the file specified by <code>$path</code> and returns as a <code>xs:base64Binary</code>.<br /> | ||
|- | |- | ||
Line 254: | Line 203: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | + | |This function writes a sequence of <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 (see [[Serialization]] for more details).<br /> | |
− | |||
− | |||
− | |This function writes a sequence | ||
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 267: | Line 213: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>file:write-binary</b>($path as xs:string, $ | + | |<code><b>file:write-binary</b>($path as xs:string, $items as xs:base64Binary) as empty-sequence()</code><br /> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | + | |This function writes a sequence of <code>xs:basex64Binary</code> <code>$items</code> to a file specified by <code>$path</code>. If the specified file already exists, it will be overwritten.<br /> | |
− | |||
− | |||
− | |This function writes a <code>xs:basex64Binary</code> | ||
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 286: | Line 229: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | + | |This function appends a sequence of <code>$items</code> to a file specified by <code>$path</code>. If the specified file does not exists, a new file is created.<br /> | |
− | |||
− | |||
− | |This function appends a sequence of <code>$items</code> | ||
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 299: | Line 239: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>file:append-binary</b>($path as xs:string, $ | + | |<code><b>file:append-binary</b>($path as xs:string, $items as xs:base64Binary) as empty-sequence()</code><br /> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | + | |This function appends a sequence of <code>xs:basex64Binary</code> <code>$items</code> to a file specified by <code>$path</code>. If the specified file does not exists, a new file is created.<br /> | |
− | |||
− | |||
− | |This function appends a sequence of <code>xs:basex64Binary</code> <code>$items</code> | ||
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 318: | Line 255: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |||
− | |||
− | |||
|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 /> | |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 /> | ||
|- | |- | ||
Line 334: | Line 268: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | + | |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 /> | |
− | |||
− | |||
− | |This function moves | ||
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' |
Revision as of 20:09, 22 April 2011
This module contains XQuery Functions to perform file system related operations, such as listing, reading, or writing files. All functions are preceded by the file:
prefix, which is linked to the http://expath.org/ns/file
namespace. This module has been aligned with the latest EXPath File Module draft from 2011 (expected to be online in a few days). BaseX 6.6.2
Contents
- 1 file:directory-separator
- 2 file:path-separator
- 3 file:exists
- 4 file:is-directory
- 5 file:is-file
- 6 file:last-modified
- 7 file:size
- 8 file:base-name
- 9 file:dir-name
- 10 file:path-to-native
- 11 file:resolve-path
- 12 file:path-to-uri
- 13 file:list
- 14 file:create-directory
- 15 file:delete
- 16 file:read
- 17 file:read-binary
- 18 file:write
- 19 file:write-binary
- 20 file:append
- 21 file:append-binary
- 22 file:copy
- 23 file:move
file:directory-separator
Signatures | file:directory-separator as xs:string |
Summary | This variable returns the directory separator used by the operating system, such as "/" or "\". |
file:path-separator
Signatures | file:path-separator as xs:string |
Summary | This variable returns the path separator used by the operating system, such as ";" or ":". |
file:exists
Signatures | file:exists($path as xs:string) as xs:boolean |
Summary | 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 | 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 | This function returns an xs:boolean indicating whether the argument $path points to an existing file. |
file:last-modified
Signatures | file:last-modified($path as xs:string) as xs:dateTime |
Summary | 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($file as xs:string) as xs:integer |
Summary | This function returns the size, in bytes, of the file specified by $path . |
Errors | FOFL0001 is raised if the specified path does not exist. FOFL0004 is raised if the specified path does not point to a file. |
file:base-name
Signatures | file:base-name($path as xs:string) as xs:integer file:base-name($path as xs:string, $suffix as xs:string) as xs:integer |
Summary | This function returns the base-name of the path specified by $path , which is the component after the last directory separator.If $suffix is specified, it will be trimmed from the end of the result. |
file:dir-name
Signatures | file:dir-name($path as xs:string) as xs:integer |
Summary | This function returns the parent directory of the path specified by $path , which is the component before the last directory separator. |
file:path-to-native
Signatures | file:path-to-native($path as xs:string) as xs:string |
Summary | This function transforms the $path argument to its native representation on the operating system. |
Errors | FOFL0000 is raised if the specified path cannot be transformed to its native representation. |
file:resolve-path
Signatures | file:resolve-path($path as xs:string) as xs:string |
Summary | This function transforms the $path argument to an absolute operating system path. |
file:path-to-uri
Signatures | file:path-to-uri($path as xs:string) as xs:string |
Summary | This function transforms the path specified by $path into a URI with the file:// scheme. |
file:list
Signatures | file:list($directory as xs:string) as xs:string* file:list($directory as xs:string, $recursive as xs:boolean) as xs:string* file:list($directory as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string* |
Summary | This function lists all files and directories found in the specified $directory . 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 in the glob syntax. If present, only those files and directories are returned that correspond to the pattern. 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 | 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() |
Summary | This function recursively deletes a file or directory specified by $path . |
Errors | FOFL0001 is raised if the specified path does not exist. FOFL0000 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 | 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 | 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() |
Summary | This function writes a sequence of $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 (see Serialization for more details). |
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, $items as xs:base64Binary) as empty-sequence() |
Summary | This function writes a sequence of xs:basex64Binary $items to a file specified by $path . If the specified file already exists, it will be overwritten. |
Errors | FOFL0004 is raised if the specified path is a directory. FOFL0008 is raised if the operation fails for some other reason. |
file:append
Signatures | file:append($path as xs:string, $items as xs:item()*) as empty-sequence() file:append($path as xs:string, $items as xs:item()*, $params as xs:node()*) as empty-sequence() |
Summary | This function appends a sequence of $items to a file specified by $path . If the specified file does not exists, a new file 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:append-binary
Signatures | file:append-binary($path as xs:string, $items as xs:base64Binary) as empty-sequence() |
Summary | This function appends a sequence of xs:basex64Binary $items to a file specified by $path . If the specified file does not exists, a new file 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 | 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 | 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. |