Get all parent folders to project root

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

Hello,

I need to figure out where an item resides inside my project. I can get parent folder with app.project.item(index).parentFolder and could loop my way through until i hit the Root but i'd rather not if there's a better way.

So, to be precise, if i have:

Code: Select all

Project Root
     |-- Folder1
          |-- Folder2
               |-- Item
and i know item index, i would like to get that as a path (/Root/Folder1/Folder2/Item).

Please tell me there's an easy way to do this... :?
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

Another question, is it possible to get item index under parent folder?

If structure is something like this:

Code: Select all

Root
     |-- FolderA
     |-- FolderB
          |-- ItemA
          |-- ItemB
          |-- ItemC
ItemC is of an index 5 but, knowing that, how would i figure out that this item is of an index 3 under its own parent folder?

Trying to do this through scripting, of course...

Thanks a bunch.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

For your first question, I don't think there isn't an easier way to get the folder path than looping through the parentFolder. That's what I would do.

The only way I can think of finding the item index in the folder is to loop through the folder items and compare to your existing item to find a match. i.e. if (item.id == folderObject.item(x).id)

Paul
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

I suspected that would be the case. Made these functions to deal with it:

Code: Select all

function getItemProjectPath(item) {
    var parent = item.parentFolder;
    var string = "";
    while (parent != app.project.rootFolder) {
        var name = "/" + parent.name;
        string = name.concat(string);
        parent = parent.parentFolder;
    }
    return string;
}

function getItemFolderIndex(item) {
    var parent = item.parentFolder;
    for (var i = 1; i <= parent.numItems; i++) {
        if (item.id == parent.item(i).id) {
            return i;
        }
    }
}
Post Reply