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

How can I get a list of rated files in folders/subfolders?

Engaged ,
Aug 27, 2011 Aug 27, 2011

I use a star rating system to select which photos I need to work on. Each subject has their own folder. Within each subject's folder are subfolders, one for each time I have a photo shoot with them. The hierarchy looks something like this.....

MainFolder

     Subject1

          Shoot1

          Shoot2

     Subject2

          Shoot1

     Subject3

          Shoot1

          Shoot2

          Shoot3

          Shoot4

     Subject4

          Shoot1

And so on. The image files are within each "Shoot" folder. The thing I'd like to accomplish is to have a way that I can start with the main folder and check through all subfolders where image files are and build a listing of all rated image files that I can parse through to see which images I need to work on.

Ideally I'd like to have them sorted from highest to lowest rating. I can do this by stepping through each folder and file within, checking the rating of each file, and continuing. What I'd really prefer to speed things up is to know if there is a way to check a folder's contents and filter it by rating. First, extract all the 5-star rated filenames, then 4-star, then 3-star, and so on. I cannot find anything in the documentation for Bridge scripting that allows for sorting/filtering folder contents. I currently have over 40,000 image files so checking through them one at a time even with a script would be a task which is why I'd like to know if there is a scripting method to filter out ratings within folders.

Any help would be greatly appreciated. I can write the script...at least most of it I think...but things would go so much nicer for me with a filter/sort.

TOPICS
Scripting
2.8K
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

correct answers 1 Correct answer

Valorous Hero , Aug 28, 2011 Aug 28, 2011

Yes it does iterate through every file, but it shouldn't take too long as Bridge won't be caching all the files.

If it is a long process, you could write the folder list out to a file and process a few at a time.

Good luck!

Translate
Valorous Hero ,
Aug 28, 2011 Aug 28, 2011

One idea would be to put them into Collections.

as an example...

#target bridge
var folders =[];
var topLevel = app.document.presentationPath;
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
//Create 5 collection to put the files into
var FiveStars = app.createCollection("Five Stars");
var FourStars = app.createCollection("Four Stars");
var ThreeStars = app.createCollection("Three Stars");
var TwoStars = app.createCollection("Two Stars");
var OneStar = app.createCollection("One Star");
for(var a in folders){
var PictureFiles = Folder(folders).getFiles(/\.(jpg|jpe|jpeg|gif|eps|dng|bmp|tif|tiff|psd|crw|cr2|rle|dib|cin|dpx|ps|pcd|pict|vda|icb...


).synchronousMetadata;
md.namespace = "http://ns.adobe.com/xap/1.0/"
Rating = "'"+md.Rating+"'";
Rating =Rating.replace(/'/g,'');
switch(Number(Rating)){
    case 0 : break; /* No Rating */
    case 1 : app.addCollectionMember(OneStar,new Thumbnail(PictureFiles

)); break;
    case 2 : app.addCollectionMember(TwoStars,new Thumbnail(PictureFiles

)); break;
    case 3 : app.addCollectionMember(ThreeStars,new Thumbnail(PictureFiles

)); break;
    case 4 : app.addCollectionMember(FourStars,new Thumbnail(PictureFiles

)); break;
    case 5 : app.addCollectionMember(FiveStars,new Thumbnail(PictureFiles

)); break;
    default : break;
    }
    }
}
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
  var fileFoldObj = fileFolderArray;
  if ( fileFoldObj instanceof File ) {  
  } else {
         destArray.push( Folder(fileFoldObj) );
  FindAllFolders( fileFoldObj.toString(), destArray );
  }
}
return destArray;
}

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
Engaged ,
Aug 28, 2011 Aug 28, 2011

Excellent! Thanks, Paul. But if I'm not mistaken, that method does iterate through each file to check ratings. I'm thinking more and more that I'm going to have to do it that way or just use the Bridge Engine's built-in filter in the preview window and select "+subfolders" from within the main album. I did it that way last night and it locked up on me 3 times and took quite awhile to do so I'm guessng a script will take longer.

I'm going to play around with the script you posted and maybe I can add my own filtering to it to make it quicker such as a selection dialog to choose which subfolders to concentrate on, a check to see if the folder has changed since the last check, etc.

Once again, thanks Paul. This was very helpful.

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
Valorous Hero ,
Aug 28, 2011 Aug 28, 2011

Yes it does iterate through every file, but it shouldn't take too long as Bridge won't be caching all the files.

If it is a long process, you could write the folder list out to a file and process a few at a time.

Good luck!

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
Engaged ,
Aug 28, 2011 Aug 28, 2011

I do have a question, Paul. Can you explain what the following lines do?

md.namespace = "http://ns.adobe.com/xap/1.0/"
Rating = "'"+md.Rating+"'";
Rating =Rating.replace(/'/g,'');

Much appreciated.

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
Valorous Hero ,
Aug 28, 2011 Aug 28, 2011

That bit of code extracts the metadata for getting the Rating.

var md = new Thumbnail(PictureFiles

).synchronousMetadata; //Thumbnail


md.namespace = "http://ns.adobe.com/xap/1.0/"  //Schema that Rating is in


Rating = "'"+md.Rating+"'";  //Set a variable to Quote + Rating Value + Quote


Rating =Rating.replace(/'/g,''); //Remove the Quotes

The quotes are there in case the Rating is not set, then you would get some rubbish and not the actual value, it's just one way to get correct values.

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
Guru ,
Aug 28, 2011 Aug 28, 2011

rating is also just a plain r/w property of the thumbnail object so if getting/putting md is slowing things down (up to 2 seconds per file) you could try that route too…

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
Valorous Hero ,
Aug 28, 2011 Aug 28, 2011

How right you are Mark, you know I am gradually going senile

This will do the same but will allow re-runs without re-creating the collections or adding duplicates.


#target bridge
var folders =[];
var topLevel = app.document.presentationPath;
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
//Create 5 collections to put the files into
var FiveStars = FourStars = ThreeStars = TwoStars = OneStar = undefined;
var colls =app.getCollections();
for(var a in colls){
    if(colls.name == "Five Stars") FiveStars= colls;
    if(colls
.name == "Four Stars") FourStars= colls;
    if(colls
.name == "Three Stars") ThreeStars= colls;
    if(colls
.name == "Two Stars") TwoStars= colls;
    if(colls
.name == "One Star") OneStar= colls;
}
if(FiveStars == undefined) FiveStars = app.createCollection("Five Stars");
if(FourStars == undefine...




).getFiles(/\.(jpg|jpe|jpeg|gif|eps|dng|bmp|tif|tiff|psd|crw|cr2|rle|dib|cin|dpx|ps|pcd|pict|vda|icb...

).rating;
if(Rating == undefined) Rating = 0;
switch(Number(Rating)){
    case 0 : break; /* No Rating */
    case 1 : if(!app.isCollectionMember(OneStar,new Thumbnail(PictureFiles

))) app.addCollectionMember(OneStar,new Thumbnail(PictureFiles

)); break;
    case 2 : if(!app.isCollectionMember(TwoStars,new Thumbnail(PictureFiles

))) app.addCollectionMember(TwoStars,new Thumbnail(PictureFiles

)); break;
    case 3 : if(!app.isCollectionMember(ThreeStars,new Thumbnail(PictureFiles

))) app.addCollectionMember(ThreeStars,new Thumbnail(PictureFiles

)); break;
    case 4 : if(!app.isCollectionMember(FourStars,new Thumbnail(PictureFiles

))) app.addCollectionMember(FourStars,new Thumbnail(PictureFiles

)); break;
    case 5 : if(!app.isCollectionMember(FiveStars,new Thumbnail(PictureFiles

))) app.addCollectionMember(FiveStars,new Thumbnail(PictureFiles

)); break;
    default : break;
    }
    }
}
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
  var fileFoldObj = fileFolderArray;
  if ( fileFoldObj instanceof File ) {  
  } else {
         destArray.push( Folder(fileFoldObj) );
  FindAllFolders( fileFoldObj.toString(), destArray );
  }
}
return destArray;
}

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
Guru ,
Aug 28, 2011 Aug 28, 2011

No problem Paul, I'll beat you 'by a country mile' to going nuts… It was the number of files in question that had me mention this… I did not test the difference but with a lot of files it could be quite dramatic… Don't forget I had issues with Collections being forgetful… They have punctuation Alzheimer’s… and beat us both to madness…

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
Engaged ,
Aug 28, 2011 Aug 28, 2011

OK. The script is working great, but not quite perfect and I'm having trouble understanding what is wrong. It's returing all the jpg files just fine. I also have psd and CR2 files that are rated. Those are not being added to the collections. I really only need it to filter by CR2 and psd files, though, and exclude jpg files. I just can't figure out why it won't return anything other than jpg file types.

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
Engaged ,
Aug 28, 2011 Aug 28, 2011

Well, for some strange reason it's now working. So just ignore my previous post.

And thank you both.

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
Valorous Hero ,
Aug 28, 2011 Aug 28, 2011

Glad its working, if you only need those two file types you can change this line as follows.

var PictureFiles = Folder(folders).getFiles(/\.(psd|cr2)$/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
Engaged ,
Aug 28, 2011 Aug 28, 2011
LATEST

Yes. I did that already along with a check to see if the image has been completed or not (a jpg file of the same name). If it has, it gets ignored (Rating=0).

I'm also ignoring specific folders in the iteration where only proofs are stored with no ratings.

Surprisingly, it takes under a minute to run through the script. Even ignoring the proofs folders, there are well over 10,000 image files to go through.

Thanks again, guys. Much appreciated.

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