Skip to content

Instantly share code, notes, and snippets.

@prestonmcgowan
Created October 10, 2019 18:51
Show Gist options
  • Save prestonmcgowan/ebd0c315a51e8e2981d1105a11394492 to your computer and use it in GitHub Desktop.
Save prestonmcgowan/ebd0c315a51e8e2981d1105a11394492 to your computer and use it in GitHub Desktop.
Recursive filesystem ls (ls -R) with MarkLogic
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