As a follow-up to this thread I have discovered an undocumented function call
that will create a file system directory:
xdmp:filesystem-directory-create($directory)
This function is used within the Admin code that is shipped with MarkLogic.
Not sure why it isn't documented as it seems to work very well. It will not
automatically create parent directories, so it is necessary to first create the
parent, then the subdirectory. The code below shows a simple sample. The
try/catch is used for the case where a parent directory might already exist and
we want to continue to create the subdirectories.
xquery version "1.0-ml";
(: Must create parent directory first :)
for $dir in ("C:/tmp/a", "C:/tmp/a/b", "C:/tmp/a/b/c")
return
try {
xdmp:filesystem-directory-create($dir)
}
catch($e) {()}
David
-----Original Message-----
From: David Scott Gurney
Sent: Thursday, December 11, 2008 7:50 PM
To: 'General Mark Logic Developer Discussion'
Subject: RE: [MarkLogic Dev General] xdmp:directory-create() doesn't seem to
work
For those that are interested, a directory can be created by using MLJAM to
make a call out to Java to do the directory creation. You will need to setup
MLJAM (see http://developer.marklogic.com/howto/tutorials/2006-05-mljam.xqy)
The code below can then be used to do the directory creation. (Obviously you
will need to change it to match your environment)
David
xquery version "0.9-ml"
module "http://mySite.createDir"
declare namespace dir = "http://mySite.createDir"
import module namespace jam = "http://xqdev.com/jam" at "/modules/jam.xqy"
define function createDirectory($directory) {
jam:start("http://localhost:8080/mljam/mljam", "mljam",
"secret"),
jam:set("newDirectory", $directory),
jam:eval('
import java.io.*;
// Create one directory
boolean success = (new File(newDirectory)).mkdir();
if (success) {
System.out.println("Directory: " + newDirectory
+ " created");
}
'),
jam:get("success"),
jam:end()
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael Blakeley
Sent: Thursday, December 11, 2008 1:11 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] xdmp:directory-create() doesn't seem to
work
Not directly, no. Depending on what you're doing, you might want to look
into XQSync
(http://developer.marklogic.com/howto/tutorials/2006-08-xqsync.xqy).
Another possibility is to write a simple web service, in a language of
your choice, that performs the directory-create on demand. Your XQuery
could POST a directory name to it, using xdmp:http-post().
-- Mike
On 2008-12-11 09:00, David Scott Gurney wrote:
> Thanks - that clarifies why I'm not seeing any directories created on the
> file system.
>
> What I really want to do is the ability to create a directory in the file
> system so that I can write a file to it with xdmp:save()
>
> xdmp:save() works very well as long as the directory already exists - hence
> the need to create the directory before performing the save operation.
>
> It looks like xdmp:filesystem-directory will only give a listing of files
> within an already existing directory. (not create one)
>
> Is there a function to create a directory on the file system?
>
> Thanks
> David
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Michael Blakeley
> Sent: Thursday, December 11, 2008 9:45 AM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] xdmp:directory-create() doesn't seem to
> work
>
> xdmp:directory-create() creates a directory in the current database. It
> may be that
> http://developer.marklogic.com/pubs/4.0/apidocs/UpdateBuiltins.html#xdmp:directory-create
> isn't clear enough about this.
>
> Perhaps you want
> http://developer.marklogic.com/pubs/4.0/apidocs/AdminBuiltins.html#xdmp:filesystem-directory
> instead?
>
> -- Mike
>
> On 2008-12-11 08:22, David Scott Gurney wrote:
>> The following code does not actually create any directories - nor does it
>> throw any errors.
>>
>> xquery version "1.0-ml";
>>
>> xdmp:directory-create("test1/"),
>> xdmp:directory-create("/test2/"),
>> xdmp:directory-create("C:\Program Files\MarkLogic\test3/"),
>> xdmp:directory-create("C:/Program Files/MarkLogic/test4/"),
>> xdmp:directory-create("C:/Program Files/MarkLogic/test5/",
>> xdmp:default-permissions()),
>> xdmp:directory-create("C:\Program Files\MarkLogic\test6/",
>> xdmp:default-permissions()),
>> xdmp:directory-create("C:/tmp/test7/", xdmp:default-permissions()),
>> xdmp:directory-create("C:\tmp\test8/", xdmp:default-permissions())
>>
>>
>> This is on WindowsXP with ML version 4.0-1
>>
>> Am I doing something wrong, or is this functionality broken? It appears
>> that both relative and absolute paths do not work.
>>
>> Thanks,
>> David
>>
>>
>> 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
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general