Changes

Jump to navigation Jump to search
1,123 bytes added ,  09:38, 26 September 2022
|- valign="top"
| '''Summary'''
|Lists all files and directories found in the specified {{Code|$dir}}. The returned paths are relative to the provided path.<br />The optional parameter {{Code|$recursive}} specifies whether sub-directories subdirectories will be traversed, too.<br />The optional parameter {{Code|$pattern}} defines a file name pattern in the [[Commands#Glob_Syntax|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|,}}).<br />
|- valign="top"
| '''Errors'''
|{{Error|not-found|#Errors}} the specified file does not exist.<br />{{Error|no-dir|#Errors}} the specified path does not point to a directory.<br />{{Error|io-error|#Errors}} the operation fails for some other reason.<br />
|- valign="top"
| '''Examples'''
| Return the contents of large {Code|.txt} files located in a specific directory and its subdirectories:
<syntaxhighlight lang="xquery">
let $root := 'path/to/files/'
for $file in file:list($root, true(), '*.txt')
let $path := $root || $file
where file:size($path) > 1000000
return file:read-text($path)
</syntaxhighlight>
|}
|- valign="top"
| '''Summary'''
|Returns the full paths to all files and directories found in the specified {{Code|$dir}}.<br/>The inverse function is {{Function||file:parent}}. The returned paths start with the specified directory. The related function {{Function||file:list}} returns relative file paths.
|- valign="top"
| '''Errors'''
|{{Error|not-found|#Errors}} the specified file does not exist.<br />{{Error|no-dir|#Errors}} the specified path does not point to a directory.<br />{{Error|io-error|#Errors}} the operation fails for some other reason.<br />
|- valign="top"
| '''Examples'''
| Return the contents of large {Code|.txt} files located in a specific directory:
<syntaxhighlight lang="xquery">
for $file in file:children('path/to/files/')
where matches($file, '.txt', 'i') and file:size($file) > 1000000
return file:read-text($$file)
</syntaxhighlight>
|}
|- valign="top"
| '''Summary'''
|Returns the full paths to all files and directories found in the specified {{Code|$dir}} and its sub-directoriessubdirectories.<br/>. The returned paths start with the specified directory. The related function {{Function||file:list}} returns creates relative file paths.
|- valign="top"
| '''Errors'''
|{{Error|not-found|#Errors}} the specified file does not exist.<br />{{Error|no-dir|#Errors}} the specified path does not point to a directory.<br />{{Error|io-error|#Errors}} the operation fails for some other reason.<br />
|- valign="top"
| '''Examples'''
| Return the contents of all {Code|.txt} files located in a specific directory and its subdirectories:
<syntaxhighlight lang="xquery">
for $file in file:descendants('path/to/files/')
where matches($file, '.txt', 'i') and file:size($file) > 1000000
return file:read-text($$file)
</syntaxhighlight>
|}
|- valign="top"
| '''Summary'''
|Recursively deletes a file or directory specified by {{Code|$path}}.<br />The optional parameter {{Code|$recursive}} specifies whether sub-directories subdirectories will be deleted, too.<br />
|- valign="top"
| '''Errors'''
|- valign="top"
| '''Summary'''
|Returns the ''current working directory'', i.e., the directory from which the query processor was started. This function returns the same result as the function call <code>file:resolve-path("")</code>.
|}
|- valign="top"
| '''Summary'''
|Returns the parent directory of the static base URI. <br/>If the Base static base URI property is undefinedor does not point to a local resource, it returns the empty sequence is returned. - If a static base URI exists, and if points to a local file pathOtherwise, this function it returns the same result as the expression {{Code|file:parent(static-base-uri())}}.
|}
;Version 7.2.1
* Updated: {{Function||file:delete}}: {{Code|$recursive}} parameter added to prevent sub-directories subdirectories from being accidentally deleted.
* Fixed: {{Function||file:list}} now returns relative instead of absolute paths.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu