For reference here is the code I'm running in a CQ session.

xquery version "0.9-ml"
define variable $module-options as element() {
                                                                <options 
xmlns="xdmp:eval"> {
                                                                                
element isolation { "different-transaction" },
                                                                                
element database { xdmp:modules-database() },
                                                                                
element modules { xdmp:modules-database() },
                                                                                
element root { xdmp:modules-root() }
                                                                } </options>
                                                }
declare namespace zip="xdmp:zip"

let $q := 'xquery version "0.9-ml"
           declare namespace zip="xdmp:zip"
           define variable $zipper as xs:string external
           let $zip := xdmp:document-get($zipper,
                                   <options xmlns="xdmp:document-get" 
xmlns:http="xdmp:http">
                                         <format>binary</format>
                                   </options>)
           let $root := fn:concat(xdmp:modules-root(),"Haze/")
           let $zlist :=
                   for $i in fn:data(xdmp:zip-manifest( $zip )/zip:[EMAIL 
PROTECTED]:encrypted="false"])
                   let $j := fn:concat($root, fn:replace($i, "\\", "/"))
                   order by $j
                   return $j
           let $list :=
                   fn:distinct-values(
                        for $name in $zlist
                        return (
                            if (fn:ends-with($name, "/")) then 
(xdmp:missing-directories($name))
                            else ($name)
                        )
                   )
            for $name in $list
            order by $name
            return (
                     if (fn:ends-with($name, "/")) then (
                         xdmp:directory-create($name)
                     )
                     else (
                         xdmp:save($name, xdmp:zip-get($zip, 
fn:substring-after($name, $root)))
                     )
                     , $name
            )
          '

return xdmp:eval($q,
                  (xs:QName('zipper'), "D:\Archive\MarkLogic\cms.zip"),
                   $module-options)

From: Keith Breinholt
Sent: Thursday, September 11, 2008 5:16 PM
To: '[email protected]'
Subject: Creating file system directories with XQuery...

Is it possible to create a directory on the file system from XQuery?

I'm having issues trying to copy/deploy XQuery modules from a zip file and 
saving it into the modules "database" when the modules database is set to 
'filesystem'.

Specifically, the xdmp:save() function does not auto-create directories like it 
does for a database, and xdmp:directory-create() does not create directories on 
the file system either.  In fact xdmp:directory-create() doesn't throw an error 
when it fails...it just returns as if it succeeded.  (Is this a bug?)

If I point my modules to 'filesystem' is there any way of creating a directory 
or am I stuck calling out to java or C#.

Keith L. Breinholt
ICS - Platform Services
801-240-7161 - w
801-602-7970 - c
"Do what you can, with what you have, where you are." - Theodore Roosevelt

----------------------------------------------------------------------
NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to