Hello. Need help with a simple modification of lxp's script (here).
I want to rename folders according to {datetaken} of .CR2 files in it, but this script stops when there are no such files (e.g. there're only JPGs, which have no datetaken), i've got
"Error at line 11, position 13
'metadata.image.datetaken' is null or not an object (0x800a138f)"
it also stops (doesn't work) if there is only one image in a folder with no {datetaken} meta.
is there a simple way to solve ерш issue?
var fsu = DOpus.FSUtil();
function OnGetNewName(getNewNameData) {
var item = getNewNameData.item;
if (!item.is_dir) return false;
var foundTag = false;
var folderEnum = fsu.ReadDir(item, 'r'); // recursive
while (!folderEnum.complete) {
var folderItem = folderEnum.Next();
if (folderItem.metadata == 'image') {
var newAlbum = folderItem.metadata.image.datetaken.Format("D#yyyy-MM-dd");
foundTag = true;
break;
}
}
return foundTag ? newAlbum : false;
}
works ok. and, Dear, lxp, can you add some line to rename folder to created date if there were no datetaken at all, e.g. for folder with JPGs only, thank you in advance
I tried so hard until I got it. Now this script inserts, at the end of the name of the selected folder, the capture date of the photos it contains.
The script can be executed directly from a button on the toolbar, but in the Function field select the option Standard function (Opus or external), no script even though it is a script.
@disablenosel:dirs
Rename PATTERN * TO *
@script jscript
var fsu = DOpus.FSUtil();
function OnGetNewName(getNewNameData) {
var item = getNewNameData.item;
if (!item.is_dir) return false;
var returnDate = item.create;
var folderEnum = fsu.ReadDir(item); // no recursivo, para recursivo... var folderEnum = fsu.ReadDir(item, 'r');
while (!folderEnum.complete) {
var folderItem = folderEnum.Next();
returnDate = folderItem.create;
if (folderItem.metadata == 'none') continue;
if (folderItem.metadata.image.datetaken == null) continue;
datetaken = folderItem.metadata.image.datetaken;
break;
}
folderEnum.Close();
var datetaken_format = datetaken.Format('D#yyyy-MM-dd');
var result = item.name + " (" + datetaken_format + ")";
return result;
}