Skip to main content
Known Participant
April 28, 2015
Answered

Creating a folder structure at a defined location on your desktop from AE via script?

  • April 28, 2015
  • 2 replies
  • 5372 views


I've written a script that creates a folder structure in my AE project view but I would like to then be able to run another script (eventually tied to a button on a GUI panel) that allows me to define where I can create a similar folder structure on my desktop or defined folder.

Is there a way to do this?

Thanks!

This topic has been closed for replies.
Correct answer David Torno

That would be extremely helpful. I really appreciate it, good luck with unpacking!


Ok, I believe I now have something that works. I've tested it a little bit in CC 2014, but have not really put it through the wringer. So use with CAUTION!!!

It may not look pretty, but it works. The only things to be aware of are that it currently does not have a special character verifier to prevent OS folder name issues. The other is that if a duplicate folder name appears within the same parentFolder (see crude example below), it will just not be created in the OS setup. This prevents overwriting folders without warning.

Example:

What is in AE.....

Folder 1

    Folder 2

    Folder 3

          Folder 4

          Folder 4    <-----Folder with a duplicate name

          Folder 5

    Folder 4    <-----Folder with a duplicate name, but is unique to it's parentFolder

What is created in OS.....

Folder 1

    Folder 2

    Folder 3

          Folder 4

          Folder 5

    Folder 4

Below is the function code, just supply one argument type of a Folder Object. This will be the new root folder to build your AE folder structure in.

var b = Folder.selectDialog("Choose a source folder.");

if(b != null){

    aeFoldersToOSFolders(b);

}

function aeFoldersToOSFolders(newRoot){

    var proj, allItems, folderCollection, folderCollectionLen, curItem, val, win, userOS, slash, newCorePath, folderNames, folderAEPath, temp;

    win = $.os.indexOf("Windows");

    win != (-1) ? userOS = "PC" : userOS = "MAC";

    userOS == ("PC") ? slash = "\\" : slash = "/";

    function getItemParentPath(endItem, ary, slash){

          if(endItem == "undefined"){

              return ary;

          }else if(endItem.name == "Root"){

              if(ary.length > 0){

                    return ary.reverse().join(slash).toString();

              }else{

                    return null;

              }

          }else{

              ary.push(endItem.name);

              var newParent = endItem.parentFolder;

              return getItemParentPath(newParent, ary, slash);

          }

    }

    proj = app.project;

    allItems = proj.numItems;

    folderCollection = new Array();

    temp = new Array();

    newCorePath = decodeURI(newRoot).toString();

    for(var i=1; i<=allItems; i++){

          curItem = proj.item(i);

          if(curItem instanceof FolderItem){

              temp.length = 0;

              folderAEPath = getItemParentPath(curItem, temp, slash);

              if(folderAEPath != null){

                    folderCollection.push(newCorePath + slash + folderAEPath);

              }

          }

    }

    folderCollectionLen = folderCollection.length;

    if(folderCollectionLen > 0){

          for(var f=0; f<folderCollectionLen; f++){

              if(Folder(folderCollection).exists == false){

                    Folder(folderCollection).create();

              }

          }

          return true;

    }else{

          return null;

    }

}

2 replies

Legend
April 28, 2015

Ok, so this is a function I had made to make root folder creation automated.

var a = new Array("099_001", "099_005", "099_010", "099_015", "099_020", "099_025");     //Array of folder names

var b = Folder.selectDialog("Choose a source folder.");     //Ask to choose a root folder

if(b != null){     //Makes sure root folder choice was not canceled

  folderCreator(a, b);     //Call folder creation function

}

/* TESTING ABOVE */

function folderCreator(arrayOfFolderNames, newFolderPath){

     var a = arrayOfFolderNames.length;

     var checkThisPath = decodeURI(newFolderPath.toString());

     var forTheseFolders, fObj;

     var userOS = null;

     var slash;

     var win = $.os.indexOf("Windows");

     win != (-1) ? userOS = "PC" : userOS = "MAC";     //Determine user OS for folder path syntax

     userOS == ("PC") ? slash = "\\" : slash = "/";     //Choose appropriate slash syntax

     for(var i=0; i<a; i++){

          forTheseFolders = checkThisPath + slash + arrayOfFolderNames;     //String concat of folder path

          fObj = Folder(forTheseFolders);     //Convert to folder object

          if(!fObj.exists){     //Makes sure folder does not already exist

               fObj.create();     //Makes new folder

          }

     }

}

Now this will create a series of folders in a selected root folder. Now if you want to have nested folders, that's a different setup and I'll have to dig up some old scripts to see if I can find it, but this should get you started hopefully.

Known Participant
April 28, 2015

Wow thank you. This definitely is getting me on the path of creating what I want. Simple being able to choose where the folder structure goes is great and something I was struggling with.

I am trying to create a root folder with nested folders within it. ex:

Project_Name>

     Projects>

           - AE

           - PS

     Elements>

           - Raster

           - Vector

     Output>

           - Dated(doesn't need to be defined)

etc.

Basically I'm trying to automate my AE workflow so I can simply open up AE and create my AE folder structure with one button and my desktop folder structure with another if that makes sense.

I'll keep working with the script provided and see where I get. Any other help is much appreciated.

Thanks again!

Legend
April 28, 2015

Yes, that is totally doable. I'm away from my computer at the moment, but can try to help out when I get back. I've done this when creating final DPX output folder structures.

Known Participant
April 28, 2015

‌That would be extremely helpful! Thanks so much. I've been trying things for a few hours and not coming up with anything so any help is much appreciated.