Skip to main content
Participating Frequently
July 29, 2007
Question

How can I create directories?

  • July 29, 2007
  • 2 replies
  • 587 views
I have written a script in Bridge CS3, running on Windows XP, that will move a folder full of images from its current location to another location. For example, it will move the folder "g:\working\2007-06-05 Stuff" to "g:\dslr\2007\06 Jun\2007-06-05 Stuff." The script is invoked by a context menu and implements part of my workflow strategy.

I am using the thumbnail moveTo() method to move the folder. In the above example, if "g:\dslr\2007\06 Jun" exists, then moveTo() works fine. However, if the directory tree does not exist, moveTo() apparently does not create parent directories automatically. So it appears I have to create the parent directory(ies) myself.

How do I create those parent directories? Just creating new Folder objects in JavaScript doesn't cause the directory to be created in the file system (as expected since Javascript is intended to protect the file system from change). I haven't found any ExtendScript tools that appear to create directories.

How can I accomplish this?

Thanks!

Guy
This topic has been closed for replies.

2 replies

Participating Frequently
July 30, 2007
Thank you; that worked perfectly (and was almost identical to what I was trying). I must have had a typo or something so that create() wouldn't work for me. Some kind of operator error anyway....

Guy
Known Participant
July 30, 2007
Guy_Scharf@adobeforums.com wrote:
How do I create those parent directories? Just creating new Folder objects in
JavaScript doesn't cause the directory to be created in the file system (as
expected since Javascript is intended to protect the file system from change). I
haven't found any ExtendScript tools that appear to create directories.
>

createFolder = function(folder) {
if (folder.exists) {
return true;
}
if (!folder.parent.exists) {
if (!createFolder(folder.parent)) {
return false;
}
}
return folder.create();
};

// usage

var fld = new Folder("/c/tmp/some/long/folder/path");
if (!createFolder(fld)) {
alert("Unable to create folder: " + fld);
}


-X