Created
October 10, 2019 18:51
-
-
Save prestonmcgowan/ebd0c315a51e8e2981d1105a11394492 to your computer and use it in GitHub Desktop.
Recursive filesystem ls (ls -R) with MarkLogic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
declare namespace dir="http://marklogic.com/xdmp/directory"; | |
declare function local:recursive-file-ls($path, $last-modified as xs:dateTime?) { | |
for $i in xdmp:filesystem-directory($path)/dir:entry | |
let $child-path := $i//dir:pathname/text() | |
let $type := $i//dir:type | |
return | |
if ($type eq "directory") then local:recursive-file-ls($child-path, $last-modified) | |
else if (fn:not(fn:empty($last-modified)) and $i//dir:last-modified ge $last-modified) then $child-path | |
else if (fn:empty($last-modified)) then $child-path | |
else () | |
}; | |
local:recursive-file-ls("/Users/username/tmp/", fn:current-dateTime() - xs:dayTimeDuration("P5D")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment