鉴于以下XQuery代码基于MarkLogic数据库中的数据生成路径并保存文件,如果没有异常,如何创建文件系统文件夹?
for $doc in collection("http://example.com/stuff")
let $folderName := name($doc/Envelope/*[1])
let $folderPath := concat("c:\temp\", $folderName, "\")
let $fileName := concat($doc/Envelope/*[1]/*:Code/text(), ".xml")
let $fullPath := concat($folderPath, $fileName)
(: Create the folder at $folderPath if it does not exist :)
return xdmp:save($fullPath,$doc)
答案 0 :(得分:4)
AFAIK没有“文件夹存在”功能,令人困惑filesystem-file-exists
实际上也适用于文件夹,所以答案是:
for $doc in collection("http://example.com/stuff")
let $folderName := name($doc/Envelope/*[1])
let $folderPath := concat("c:\temp\", $folderName, "\")
let $fileName := concat($doc/Envelope/*[1]/*:Code/text(), ".xml")
let $fullPath := concat($folderPath, $fileName)
let $_ := if(xdmp:filesystem-file-exists($folderPath)) then () else xdmp:filesystem-directory-create($folder)
return xdmp:save($fullPath,$doc)