Difference between revisions of "File Module"
Jump to navigation
Jump to search
m (Text replace - "| valign='top' | " to "| ") |
m (Text replace - "| valign='top' width='90' |" to "| width='90' |") |
||
Line 4: | Line 4: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>$file:directory-separator</b> as xs:string</code><br /> | |<code><b>$file:directory-separator</b> as xs:string</code><br /> | ||
|- | |- | ||
Line 14: | Line 14: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>$file:path-separator</b> as xs:string</code><br /> | |<code><b>$file:path-separator</b> as xs:string</code><br /> | ||
|- | |- | ||
Line 24: | Line 24: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:exists</b>($path as xs:string) as xs:boolean</code><br /> | |<code><b>file:exists</b>($path as xs:string) as xs:boolean</code><br /> | ||
|- | |- | ||
Line 34: | Line 34: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:is-directory</b>($path as xs:string) as xs:boolean</code><br /> | |<code><b>file:is-directory</b>($path as xs:string) as xs:boolean</code><br /> | ||
|- | |- | ||
Line 44: | Line 44: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:is-file</b>($path as xs:string) as xs:boolean</code><br /> | |<code><b>file:is-file</b>($path as xs:string) as xs:boolean</code><br /> | ||
|- | |- | ||
Line 54: | Line 54: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:last-modified</b>($path as xs:string) as xs:dateTime</code><br /> | |<code><b>file:last-modified</b>($path as xs:string) as xs:dateTime</code><br /> | ||
|- | |- | ||
Line 67: | Line 67: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:size</b>($file as xs:string) as xs:integer</code><br /> | |<code><b>file:size</b>($file as xs:string) as xs:integer</code><br /> | ||
|- | |- | ||
Line 80: | Line 80: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:base-name</b>($path as xs:string) as xs:string</code><br /><code><b>file:base-name</b>($path as xs:string, $suffix as xs:string) as xs:string</code><br /> | |<code><b>file:base-name</b>($path as xs:string) as xs:string</code><br /><code><b>file:base-name</b>($path as xs:string, $suffix as xs:string) as xs:string</code><br /> | ||
|- | |- | ||
Line 90: | Line 90: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:dir-name</b>($path as xs:string) as xs:string</code><br /> | |<code><b>file:dir-name</b>($path as xs:string) as xs:string</code><br /> | ||
|- | |- | ||
Line 100: | Line 100: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:path-to-native</b>($path as xs:string) as xs:string</code><br /> | |<code><b>file:path-to-native</b>($path as xs:string) as xs:string</code><br /> | ||
|- | |- | ||
Line 113: | Line 113: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:resolve-path</b>($path as xs:string) as xs:string</code><br /> | |<code><b>file:resolve-path</b>($path as xs:string) as xs:string</code><br /> | ||
|- | |- | ||
Line 123: | Line 123: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:path-to-uri</b>($path as xs:string) as xs:string</code><br /> | |<code><b>file:path-to-uri</b>($path as xs:string) as xs:string</code><br /> | ||
|- | |- | ||
Line 133: | Line 133: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<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 /> | |<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 /> | ||
|- | |- | ||
Line 146: | Line 146: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:create-directory</b>($directory as xs:string) as empty-sequence()</code><br /> | |<code><b>file:create-directory</b>($directory as xs:string) as empty-sequence()</code><br /> | ||
|- | |- | ||
Line 160: | Line 160: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | 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><br /> | |<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 /> | ||
|- | |- | ||
Line 173: | Line 173: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:read-text</b>($path as xs:string) as xs:string</code><br /><code><b>file:read-text</b>($path as xs:string, $encoding as xs:string) as xs:string</code><br /> | |<code><b>file:read-text</b>($path as xs:string) as xs:string</code><br /><code><b>file:read-text</b>($path as xs:string, $encoding as xs:string) as xs:string</code><br /> | ||
|- | |- | ||
Line 186: | Line 186: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:read-text-lines</b>($path as xs:string) as xs:string</code><br /><code><b>file:read-text-lines</b>($path as xs:string, $encoding as xs:string) as xs:string*</code><br /> | |<code><b>file:read-text-lines</b>($path as xs:string) as xs:string</code><br /><code><b>file:read-text-lines</b>($path as xs:string, $encoding as xs:string) as xs:string*</code><br /> | ||
|- | |- | ||
Line 199: | Line 199: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:read-binary</b>($path as xs:string) as xs:base64Binary</code><br /> | |<code><b>file:read-binary</b>($path as xs:string) as xs:base64Binary</code><br /> | ||
|- | |- | ||
Line 212: | Line 212: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:write</b>($path as xs:string, $items as item()*) as empty-sequence()</code><br /><code><b>file:write</b>($path as xs:string, $items as item()*, $params as xs:node()*) as empty-sequence()</code><br /> | |<code><b>file:write</b>($path as xs:string, $items as item()*) as empty-sequence()</code><br /><code><b>file:write</b>($path as xs:string, $items as item()*, $params as xs:node()*) as empty-sequence()</code><br /> | ||
|- | |- | ||
Line 227: | Line 227: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | 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*) as empty-sequence()</code><br /> | ||
|- | |- | ||
Line 240: | Line 240: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:append</b>($path as xs:string, $items as item()*) as empty-sequence()</code><br /><code><b>file:append</b>($path as xs:string, $items as item()*, $params as xs:node()*) as empty-sequence()</code><br /> | |<code><b>file:append</b>($path as xs:string, $items as item()*) as empty-sequence()</code><br /><code><b>file:append</b>($path as xs:string, $items as item()*, $params as xs:node()*) as empty-sequence()</code><br /> | ||
|- | |- | ||
Line 253: | Line 253: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:append-binary</b>($path as xs:string, $items as xs:base64Binary*) as empty-sequence()</code><br /> | |<code><b>file:append-binary</b>($path as xs:string, $items as xs:base64Binary*) as empty-sequence()</code><br /> | ||
|- | |- | ||
Line 266: | Line 266: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | 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) as empty-sequence()</code><br /> | ||
|- | |- | ||
Line 279: | Line 279: | ||
{| | {| | ||
|- | |- | ||
− | | | + | | width='90' | '''Signatures''' |
|<code><b>file:move</b>($source as xs:string, $target as xs:string) as empty-sequence()</code><br /> | |<code><b>file:move</b>($source as xs:string, $target as xs:string) as empty-sequence()</code><br /> | ||
|- | |- |
Revision as of 00:43, 26 May 2012
This XQuery Module contains functions and variables related to file system operations, such as listing, reading, or writing files. All functions are preceded by the file:
prefix, which is linked to the statically declared http://expath.org/ns/file
namespace. This module has been aligned with the latest EXPath File Module draft from 2011 (expected to be online soon).
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-text
- 17 file:read-text-lines
- 18 file:read-binary
- 19 file:write
- 20 file:write-binary
- 21 file:append
- 22 file:append-binary
- 23 file:copy
- 24 file:move
- 25 Changelog
$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 | 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 | 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 | 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 | 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 | Returns the size, in bytes, of the file specified by $path . |
Errors | FOFL0001 is raised if the specified file does not exist. FOFL0004 is raised if the specified file points to a directory. |
file:base-name
Signatures | file:base-name($path as xs:string) as xs:string file:base-name($path as xs:string, $suffix as xs:string) as xs:string |
Summary | 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:string |
Summary | 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 | 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 | 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 | 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 | 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 sub-directories will be traversed, too.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 | FOFL0003 is raised if the specified path does not point to a directory. FOFL0000 is raised if the operation fails for some other reason. |
file:create-directory
Signatures | file:create-directory($directory as xs:string) as empty-sequence() |
Summary | Recursively creates the directories specified by $directory . |
Errors | FOFL0002 is raised if a file with the same path already exists. FOFL0000 is raised if the operation fails for some other reason. |
file:delete
Template:Mark $recursive
parameter added to prevent sub-directories from being accidentally deleted.
Signatures | file:delete($path as xs:string) as empty-sequence() file:delete($path as xs:string, $recursive as xs:boolean) as empty-sequence() |
Summary | Recursively deletes a file or directory specified by $path .The optional parameter $recursive specifies whether sub-directories will be deleted, too. |
Errors | FOFL0001 is raised if the specified path does not exist. FOFL0000 is raised if the operation fails for some other reason. |
file:read-text
Signatures | file:read-text($path as xs:string) as xs:string file:read-text($path as xs:string, $encoding as xs:string) as xs:string |
Summary | 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. FOFL0005 is raised if the specified encoding is not supported, or unknown. FOFL0000 is raised if the operation fails for some other reason. |
file:read-text-lines
Signatures | file:read-text-lines($path as xs:string) as xs:string file:read-text-lines($path as xs:string, $encoding as xs:string) as xs:string* |
Summary | Reads the textual contents of the file specified by $path and returns it as a sequence of xs:string items.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. FOFL0005 is raised if the specified encoding is not supported, or unknown. FOFL0000 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 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. FOFL0000 is raised if the operation fails for some other reason. |
file:write
Signatures | file:write($path as xs:string, $items as item()*) as empty-sequence() file:write($path as xs:string, $items as item()*, $params as xs:node()*) as empty-sequence() |
Summary | 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).It can be specified as
|
Errors | FOFL0004 is raised if the specified path is a directory. FOFL0000 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 | 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. FOFL0000 is raised if the operation fails for some other reason. |
file:append
Signatures | file:append($path as xs:string, $items as item()*) as empty-sequence() file:append($path as xs:string, $items as item()*, $params as xs:node()*) as empty-sequence() |
Summary | 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. FOFL0000 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 | 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. FOFL0000 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 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. FOFL0002 is raised if the specified source is a directory and the target is a file. FOFL0003 is raised if the parent of the specified target is no directory. FOFL0000 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 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. FOFL0002 is raised if the specified source is a directory and the target is a file. FOFL0003 is raised if the parent of the specified target is no directory. FOFL0000 is raised if the operation fails for some other reason. |
Changelog
Version 7.2.1
- Updated: file:delete:
$recursive
parameter added to prevent sub-directories from being accidentally deleted. - Fixed: file:list now returns relative instead of absolute paths.