Hi, Dayro:

The deletion is only committed at the end of the statement, so the file being 
deleted still exists when the contents of the directory are checked.

You could use xdp:eval() to execute the deletion and the directory check in 
separate statements, or your module could just execute two statements 
(separated by a semicolon), with the first statement performing the deletion 
and the second performing the check.

Out of curiosity, is there a reason to perform the check with 
xdmp:directory-properties() instead of xdmp:directory()?


Erik Hennum

________________________________
From: [email protected] 
[[email protected]] on behalf of Dayro Longas 
[[email protected]]
Sent: Thursday, August 22, 2013 12:42 PM
To: [email protected]
Subject: [MarkLogic Dev General] Problem deleting file and folder

Hi,

There is a file with uri /error/file.xml, the attached code, it deletes the 
file, then a query is made to check if there are files remaining in the folder, 
if there are no more files then it deletes the folder.
The problem is that the folder is not getting deleted. Any ideas why?
Keep in mind that if there are other files in the folder it shouldn't be 
deleted.

let $uri := "/error/file.xml"
let $fileName := fn:tokenize($uri, "/")[fn:last()]
let $folder := fn:tokenize($uri, $fileName)[1]
let $delete-file := xdmp:document-delete($uri)
return
    if(fn:not(xdmp:directory-properties($folder, 
"infinity")[fn:not(.//prop:directory)])) then
        xdmp:directory-delete($folder)
    else ()


Regards,

--

Dayro Longas
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to