Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active December 15, 2015 04:08
Show Gist options
  • Select an option

  • Save caschwartz/5198882 to your computer and use it in GitHub Desktop.

Select an option

Save caschwartz/5198882 to your computer and use it in GitHub Desktop.
XQuery - Query filesystem to load PDF files and modify PDF filenames
xquery version "1.0-ml";
(: 3/27/13 Query the filesystem to add finalized PDFs to a MarkLogic database using the <dc:identfier> value for the filenames :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace localtei = "http://my.local.tei.customized.schema/tei";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
for $teiDoc in fn:collection()
let $newID := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:identifier
let $sourceID := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:source
let $filenames := xdmp:filesystem-directory("c:\my-pdf-files")/dir:entry/dir:filename
for $filename in $filenames
let $fileLocation := $pdfFile/following-sibling::dir:pathname
where $sourceID = $filename
return xdmp:document-insert(fn:concat("/PDF/youth/", fn:data($newID), ".pdf"), xdmp:external-binary($fileLocation))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment