Loop Through Folders
Hi,
I have the following code. It edits the metadata of a file and it works as needed, apart from the fact you have to be in the folder of images in order to edit the metadata of those images. What do I need to change in order for me to open up just the parent directory and for the script to go through all the child pages one by one, executing the script?
#target bridge
if( BridgeTalk.appName == "bridge" ) {
var vfRename = new MenuElement( "command", "VF Rename", "at the end of Tools" , "vfRename01" );
}
vfRename.onSelect = function () {
app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
for(var a in thumbs){
var f =thumbs.spec;
var parts = decodeURI(f.name).replace(/- \d+.jpg$/i,'').split('&&&');
setMetadata( File(f), parts )
}
function setMetadata( file, parts ){
var Title = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Desc = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Author = parts[2].toString();
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
var xmp = xmpf.getXMP();
xmp.deleteProperty(XMPConst.NS_DC, "title");
xmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT);
xmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.appendArrayItem(XMPConst.NS_DC, "creator", Author, 0, XMPConst.ARRAY_IS_ORDERED);
for(var s in parts){
xmp.appendArrayItem(XMPConst.NS_DC, "subject", parts
, 0,XMPConst.PROP_IS_ARRAY);}
if (xmpf.canPutXMP( xmp )) {
xmpf.putXMP( xmp );
}
xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
}
}
