Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I create directories?

Community Beginner ,
Jul 29, 2007 Jul 29, 2007
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
TOPICS
Scripting
539
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 29, 2007 Jul 29, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 29, 2007 Jul 29, 2007
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines