-
Recursively search folders from a script
Hey all,
I’m working on a script that imports elements from other aep files. When an aep file is imported, AE creates a folder for that file. I’m looking for a way to recursively search through my project, and return once it finds my item.
My real question here is, what’s the ‘root’ folder of an aep project? If I want to start from the top, what should I pass the initial function call? If I don’t pass it anything, it hangs.
Just an aside: I really love the scripting capabilities in AE, but man, some things just feel so primitive, such as iterating through an entire project to select an item by name. Adobe, if you’re hearing this, it’d be swell if a project maintained an array of AVItems that could be accessed by their names as well as indices.
Here’s my sample function:
////////////////////////////////////////////////////////////////////////////
function getItem(folder){
///////////////////////////////////////////////////////////////////////////
var myItem= "myItem.mov"; // Item name
var f = null; // Footagefor (var i = 1; i <= a.numItems; i++){
f = a.item(i);
if (f instanceof FolderItem){
getItem(f);
break;
}
if (f.name == myItem&& f instanceof FootageItem){
break;
}
f = null;
}if (f == null){
alert("Couldn't locate " + myItem+ "!");
} else{
c.layers.add(f); //c = app.project.activeItem
return;
}
}
Notwithstanding that this will add the footage once per level of recursion, can anybody let me know what to pass in initially?
Thanks,
Chris