Skip to main content
Inspiring
August 27, 2011
Answered

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

  • August 27, 2011
  • 3 replies
  • 2879 views

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.

This topic has been closed for replies.
Correct answer Paul Riggott

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!

3 replies

jugenjuryAuthor
Inspiring
August 28, 2011

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

And thank you both.

Paul Riggott
Inspiring
August 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);

jugenjuryAuthor
Inspiring
August 28, 2011

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.

jugenjuryAuthor
Inspiring
August 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.

Paul Riggott
Inspiring
August 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|vst|wbm|sct|pbm|flm|psb|exr|pcx|pdp|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|raw)$/i);
for(var p in PictureFiles){
var Rating =0;
var md = new Thumbnail(PictureFiles

).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;
}

jugenjuryAuthor
Inspiring
August 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.

Paul Riggott
Inspiring
August 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…


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 == undefined) FourStars = app.createCollection("Four Stars");
if(ThreeStars == undefined) ThreeStars = app.createCollection("Three Stars");
if(TwoStars == undefined) TwoStars = app.createCollection("Two Stars");
if(OneStar == undefined) 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|vst|wbm|sct|pbm|flm|psb|exr|pcx|pdp|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|raw)$/i);
for(var p in PictureFiles){
var Rating  = new Thumbnail(PictureFiles

).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;
}