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

addFolder script only create folder once

New Here ,
Oct 24, 2021 Oct 24, 2021

I'm making a script that creates a "hero" folder, a "clips" folder and moves the footage into the "clips" folder, and the "clips" folder to the "hero" folder.

My problem is that it creates multiple "hero" folders for footage that has the same name. I need to implement a check if the "hero" folder already exists in my project, I've been trying all day but got nowhere, can someone help out?

var items = app.project.selection;

    for (var i = 0; i < items.length; i++) {
        //create Folder
        var heroName = item.name.split(' ')[0];
        var heroFolder = app.project.items.addFolder(heroName);
        var clipFolder = app.project.items.addFolder(item.name);
        heroFolder.parentFolder = items[i].parentFolder;
        clipFolder.parentFolder = heroFolder;
            //move Source Footage
        items[i].parentFolder = clipFolder; 
}

 

TOPICS
Scripting
128
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 Expert ,
Oct 25, 2021 Oct 25, 2021

The best solution is to write a function like

getOrCreateFolder(name){

/*

iterate over all items of the root folder and check if one of them is a folder and has the given name.
If so, return this folder, otherwise create a new folder and return it

*/

}

Then use this function instead of your addFolder call.

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
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
Contributor ,
Oct 29, 2021 Oct 29, 2021
LATEST

If you are doing a loop and adding stuff, it's better to do a reverse loop. That way, newly created items do not get added to the total length for the loop. Something like this.
for (var i = items.length ; i >0; i--) {


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