Skip to main content
Participating Frequently
April 22, 2020
Answered

Can i create folders and sub-folders with the .ai name? SCRIPT

  • April 22, 2020
  • 1 reply
  • 2696 views

Hi to everybody!

Im using a script that takes a .ai document and save it in 4 different folders that i have.
I want to make them and also subfolders with an script, but io have no idea to do it. Can somebody share some code to make it?


Example:

 

Original folder:

1.ai

2.ai

 

 

1 /subfolder 1/ subsubfolder1/1.pdf

1 /subfolder 1/ subsubfolder2/1.png

1 /subfolder 2/ subsubfolder1/1.jpeg

1 /subfolder 2/ subsubfolder2/1.ai

 

2 /subfolder 1/ subsubfolder1/2.pdf

2 /subfolder 1/ subsubfolder2/2.png

2 /subfolder 2/ subsubfolder1/2.jpeg

2 /subfolder 2/ subsubfolder2/2.ai

 

If somebody can help me i will apreciate it a lot!!

 

THANKS!

This topic has been closed for replies.
Correct answer Silly-V

You can get the name of the current document with app.activeDocument.name , put that into a variable and also make sure your 4 different folder names are in an array that can be looped with the code such as in my example. Store the whole path in this array like so:

var ImportantFolders = [

  "C:/path start/path/My Folder1",

  "C:/path start/path/My Folder2",

  "C:/path start/path/My Folder3",

  "C:/path start/path/My Folder4"

]

 

When you loop through them to create your folders, make a variable inside the loop which makes the a new folder object with the path from your array concatenated with the current file name.

Also it may be a good idea to take out the file extension from the document name.

 

var doc = app.activeDocument;
var thisFolder;
var docNameWithoutExtension;
for(var i = 0; i < ImportantFolders.length; i++){
  docNameWithoutExtension = doc.name.replace(/\..+$/, "");
  thisFolder = Folder(ImportantFolders[i] + "/" + docNameWithoutExtension);
  thisFolder.create();
}

 

1 reply

Silly-V
Legend
April 22, 2020

Here is how you make folders using a pre-supplied array of names you wish:

 

var startFolder = Folder("~/Desktop");
var foldersToMake = ["first folder", "second folder", "third folder"];
var thisNewFolder, thisNewFolderName;
for(var i=0; i<foldersToMake.length; i++){
  thisNewFolderName = foldersToMake[i];
  // automatically converts from Folder object to string using toString() method automatically
  thisNewFolder = Folder(startFolder + "/" + thisNewFolderName);
  // not sure if this is necessary, but probably good to check it it already exists.
  if (!(thisNewFolder.exists)) {
    thisNewFolder.create();
  }
}

 

XabiAuthor
Participating Frequently
April 22, 2020

Thank you very much Silly-V!

I tried but Ilustrator dont do nothing!
Its possible to take the .ai name and make the upper folder with the .ai name?

 

Thank you very much!