Copy link to clipboard
Copied
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!
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 overwri
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
So I'm using this method for my folder creation inside of my AE project panel. Can I alter it to do the same method for the folder creation on my computer?
function makeFolder(folderName, folderParent) {
var newFolder = proj.items.addFolder(folderName); // Creates folder and names it the folderName input
if(folderParent) newFolder.parentFolder = folderParent; // puts this folder inside of the folderParent input if available
return newFolder;
}
This way I was able to define the folder creation but also say an if statement that allowed me to create the folders names like this instead:
var comps = makeFolder("01-COMPOSITIONS");
var date = makeFolder("DATE", comps);
Copy link to clipboard
Copied
I was unable to find any already existing code in my collection that did nested folders, so I started to write some code and then hit a few hurdles. As it always goes. I need to figure out a few steps in how to store the info in a way that can read the AE folder structure and save an array of folder objects to match the same creation in the OS.
Can I alter it to do the same method for the folder creation on my computer?
Your function works great for a fast nested folder creation in AE, but there would need to be a big alteration for it to work for OS folder creation since you need to define Folder objects for each folder created. Another hiccup I ran into myself was that you also need to verify duplicate names so you don't overwrite a folder by accident. If you have a predefined structure that is unique, then this isn't a problem, but in AE it is possible to create a series of folders with the exact same name together since each item has a unique ID number. In the OS you cannot do this as the dup folder will just save over the other. This creates a bit of a tricky situation where you need to increment the names. This effectively changes your folder structure a bit if there are dup names in a single folder. I'm still looking into it though.
Copy link to clipboard
Copied
Yeah I am basically running into a wall with this. I can make all the main folders but nesting is still an issue.
I think overall the folder structure on my desktop might not necessarily need to be the exact same as my AE folder structure if that is a hurdle you are running into.
Because something like "compositions" I would only use inside of AE.
I really appreciate the help. Its a fun but frustrating process!
Thanks again!
Copy link to clipboard
Copied
Hey David,
I've been still stumped about the nested folder issue. Everything I try it just throws it outside in the main root folders.
Let me know if you ever dig up those old scripts
Thanks again.
Ben
Copy link to clipboard
Copied
Hi Ben,
I will try to look back into it again. I just finished a move a few weeks ago and am still getting equipment up and running at home.
Copy link to clipboard
Copied
That would be extremely helpful. I really appreciate it, good luck with unpacking!
Copy link to clipboard
Copied
Got it. Give me a moment to clean it up.
Copy link to clipboard
Copied
Scratch that, almost have it.
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
Thanks so much David,
This worked out super well. Sorry it too me so long to let you know it worked.
Of course now I have one more question
If I wanted to create a folder structure that is only defined within the script i.e.
Folder 1
Folder 2
Folder 3
Folder 4
Folder 4
Would I just replace the function "aefolderstofolders" with this folder structure list somehow? I basically want to literally write out the folders and names I want within the script to be written to a specific folder because too many people are having random folders in their AE project saved off.
Really appreciate the help. Thanks so much.
Copy link to clipboard
Copied
If you want to hard code the folder structure, then yes you could create a function called "myDefaultFolders(newRoot)" or something. Making sure to also include the same argument so the user can pick the starting location.
You would then just need to list out your defined folder paths in an array for convenience.
So say you keep the choose your folder code...
var b = Folder.selectDialog("Choose a source folder.");
if(b != null){
myDefaultFolders(b); //Call your new function
}
You would still need some aspects from the old function, like the OS check to keep the folder paths both Win and Mac compatible. Also to keep your default folders easily changeable, I would list them out in an array via index assignment. I adjusted the function below. Verify it before proceeding as I have not tested it yet.
function myDefaultFolders(newRoot){
var folderCollection, folderCollectionLen, userOS, slash, newCorePath;
slash = ($.os.indexOf("Windows") != (-1) ? "//" : "\"; //Inline if statement to consolidate the OS check
folderCollection = new Array(); //List your folder paths separately in an array for easy looping later.
folderCollection[0] = "myFirstFolder"+slash+"myFirstSubFolder";
folderCollection[1] = "mySecondFolder"+slash+"mySecondSubFolder";
//And so on for more folders....
newCorePath = decodeURI(newRoot).toString();
folderCollectionLen = folderCollection.length;
if(folderCollectionLen > 0){
for(var f=0; f<folderCollectionLen; f++){
if(Folder(newCore+slash+folderCollection
).exists === false){ Folder(folderCollection
).create(); }
}
return true;
}else{
return null;
}
}
Copy link to clipboard
Copied
Thanks a lot David, this is exactly what I was looking for and getting me on the right track. I'm finally understanding how some of this works.
The only issue I'm having as of now is some problems with line 3. It's acting as if everything after the backslash is text rather than code. It turns yellow.
Any ideas?
Again thanks so much for putting in the time to help me.
Ben
Copy link to clipboard
Copied
Okay actually I think it's because the backslash and forward slash are just switched around so that solved the problem of everything turning into basic text.
However still not able to make this fully work.
Copy link to clipboard
Copied
Hi Ben, sorry for the late reply, I just finished getting married so things have been crazy for awhile.
You are correct, I goofed and flopped the backslash values. It should be...
slash = ($.os.indexOf("Windows") != (-1) ? "\\" : "/"; //Inline if statement to consolidate the OS check
Which part seems to fail at this point?
Copy link to clipboard
Copied
Hey David,
Thanks for the response and congrats!!!!
I think I need to put a ")" in the line of code you fixed the slashes on but even when I do that the script isn't successfully completing. It prompts me to choose the folder in which the new folders will be saved and then nothing after I hit open.
For reference I've compiled the code you have come up with, with the proper edits below (sorry not sure how to add the numbered code look). Not sure what's wrong. Must be the writing folders part?
Really appreciate the help. I'm learning a ton from this.
function directoryStructure(){
var b = Folder.selectDialog("Choose a source folder.");
if(b != null){
myDefaultFolders(b);
}
}
function myDefaultFolders(newRoot){
var folderCollection, folderCollectionLen, userOS, slash, newCorePath;
slash = ($.os.indexOf("Windows") != (-1) ? "\\" : "/"); //Inline if statement to consolidate the OS check
folderCollection = new Array(); //List your folder paths separately in an array for easy looping later.
folderCollection[0] = "myFirstFolder"+slash+"myFirstSubFolder";
folderCollection[1] = "mySecondFolder"+slash+"mySecondSubFolder";
//And so on for more folders....
newCorePath = decodeURI(newRoot).toString();
folderCollectionLen = folderCollection.length;
if(folderCollectionLen > 0){
for(var f=0; f<folderCollectionLen; f++){
if(Folder(newCore+slash+folderCollection
Folder(folderCollection
}
}
return true;
}else{
return null;
}
}
Copy link to clipboard
Copied
For future reference, you can do the syntax highlighting in these posts by clicking the top right "Use advanced editor". Select the text you want to highlight, then clicking the ">>" icon, and choose "Syntax Highlighting" then "javascript".
I made a few typos in that code. Shows how jumbled my brain was at the time.
- First the variable newCorePath was labeled as newCore in original line 16, fixed in line 30 below.
- I also checked if the newCorePath existed, but forgot to add it to the creation line. I fixed this and consolidated the code a bit with lines 30-33 below.
This should now work.
directoryStructure();
function directoryStructure(){
var b = Folder.selectDialog("Choose a source folder.");
if(b != null){
myDefaultFolders(b);
}
}
function myDefaultFolders(newRoot){
var folderCollection, folderCollectionLen, userOS, slash, newCorePath, curFolder;
slash = $.os.indexOf("Windows") != (-1) ? "\\" : "/"; //Inline if statement to consolidate the OS check
folderCollection = new Array(); //List your folder paths separately in an array for easy looping later.
folderCollection[0] = "myFirstFolder"+slash+"myFirstSubFolder";
folderCollection[1] = "mySecondFolder"+slash+"mySecondSubFolder";
//And so on for more folders....
newCorePath = decodeURI(newRoot).toString();
folderCollectionLen = folderCollection.length;
if(folderCollectionLen > 0){
for(var f=0; f<folderCollectionLen; f++){
curFolder = Folder(newCorePath+slash+folderCollection
); if(curFolder.exists === false){
curFolder.create();
}
}
return true;
}else{
return null;
}
}
Copy link to clipboard
Copied
It worked perfectly!
I should have seen that newCorePath wasn't actually being created anywhere. Thanks for walking me through the process and mistakes as well.
Can't thank you enough for the help with this.
Congrats again!
Ben
Copy link to clipboard
Copied
Thank you and you're welcome. Wish all issues were that easy to fix.
Copy link to clipboard
Copied
Alright last question I promise, I'm sure it's a simple one.
In the folder creation method you have laid out, how do I use this process to create multiple folders inside of one folder?
So you have:
folderCollection[0] = "myFirstFolder"+slash+"myFirstSubFolder";
folderCollection[1] = "mySecondFolder"+slash+"mySecondSubFolder";
This works well if I want to make
myFirstFolder
myFirstSubFolder
But I need to create something more like
myFirstFolder
myFirstSubFolder
myFirstSubSubFolder
myThirdSubFolder
myFourthSubFolder
So basically referencing a sub folder and putting multiple folders into it.
Is there something easy I'm not understanding? I tried adding just a "+" instead of the slash etc.
Thanks.
Copy link to clipboard
Copied
Alright I figured it out. I thought making folderCollecdtion[1] starting with master would overwrite it but it does not.
Thanks!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now