import folder into After Effects CC by using ExtendScript
Copy link to clipboard
Copied
Hi, I am trying to create a function to import folder by using Adobe Extendscript into AE CC2018. The function should be same as AE import folder function. Please see attachment below.
Attachment below is result in AE after "Import Folder" button is pressed.
I try to using import file method to import folder, but with no luck.
app.project.importFile(new ImportOptions(new Folder("C:\\Users\\Username\\Desktop\\type\\line")));
After Effects error: File can not be opened is show out.
Hopefully any AE master can help me solve my problem. Thank you very mucher!
Copy link to clipboard
Copied
From the docs (http://docs.aenhancers.com/general/project/#project-importfile), you can import with dialog. This should be the one from your first screenshot.
To get the same functionality without dialog, I think you have to import file by file. In other words: cycling through every file in a given folder with a for- or while-loop.
But maybe there is another way - let's wait what the scripting guys say.
*Martin
Copy link to clipboard
Copied
Hi @martinr84659894, very thanks for your reply!
Ya, I currently writing a similar script. Get folder name by looping through entire folder and create folder in AE. At the end import file to specific folder.
I will post my script in here after done
Copy link to clipboard
Copied
I believe this should do what you need!
var folder = new Folder;
folder = folder.selectDlg("Please select a folder");
if(folder.exists) {
var files = folder.getFiles();
importFiles(files, folder.name.replace(/%20/g, " "));
}
function importFiles(files, folderName) {
app.beginSuppressDialogs();
// additionally you can create the folder in AE to put all your imported files into
var folder = app.project.items.addFolder(folderName);
var imported;
for(var i = 0; i < files.length; i++) {
// only import it if its not a folder
if(files[i].name.indexOf(".") != -1) {
imported = app.project.importFile(new ImportOptions(files[i]));
imported.parentFolder = folder;
}
}
app.endSuppressDialogs(false);
}
This particular script avoids folders, and doing a deep search to recreate ANY given folder hierarchy would require a bit more.
Copy link to clipboard
Copied
Thanks for your reply, I already tried your script. The script is working if multiple subfolders exists.
Let say my folder is "~/type/line/images/####.exr". If I choose "type" folder, the script will only import a blank folder without next subfolder.
nothing inside "type" folder
The script is worked if without subfolder. Example: "~/type/####.exr"
Worked when "type" folder have image files
Thanks!
Copy link to clipboard
Copied
Yes, as mentioned it's going to be a bit more complicated to do n number of folders. You will need to assume each file can be a file or folder, in which case you can add an else statement to the current for loop. Inside the else would be for folder cases, where you could then create another folder using:
app.project.items.addFolder(folderName);
and then parent it to the previously created folder with
folder.parentFolder = folderObject;
Then with your new subfolder, you can use recusion to check if that subfolder has any more files, and continue until you've done a deep re-creation of all the folders.
Copy link to clipboard
Copied
Certainly! Here's a professional answer in points on how to import a folder into After Effects CC using ExtendScript:
Navigate to the Project Panel:
- In your ExtendScript code, use the app.project.rootFolder property to access the root folder of the After Effects project.
Specify the Folder Path:
- Set the folder path of the directory you want to import using the Folder object in ExtendScript. For example, var folderPath = new Folder("C:/Path/To/Your/Folder");.
Check if Folder Exists:
- Ensure the folder exists by using the exists property of the Folder object. If it doesn't exist, handle the error appropriately.
Import Folder Content:
- Utilize the importFile() or importFileWithDialog() method in ExtendScript to import files from the specified folder. Loop through the files in the folder and use the File object to create footage items in After Effects.
Organize Imported Items:
- Optionally, you can organize the imported items in After Effects by creating and utilizing folders within the project. This can be achieved using the app.project.rootFolder.items.addFolder(Canuckle Today method.
Display Success Message:
- After successfully importing the folder content of , display a message or log to confirm the completion of the task. For instance, $.writeln("Canuckle Today Words successfully imported into After Effects.");.
Handle Errors Gracefully:
- Implement error handling mechanisms to gracefully manage issues such as non-existent folders, file format mismatches, or any other potential problems during the import process.
Close the ExtendScript Script:
- End your ExtendScript by releasing any resources and closing the script in a clean manner. This ensures the script execution doesn't have lingering effects.
Documentation and Comments:
- Document your code with comments to explain its purpose and any critical steps. This aids in understanding and maintaining the script in the future.
Testing:
- Before finalizing the script, thoroughly test it with various folder structures to ensure robustness and compatibility with different scenarios.

