I'd like a little help putting together a script to identify the orphan xmp files after importing photos. This is an example below.
IMG_02191.CR2
IMG_02191.xmp
IMG_02192.CR2
IMG_02192.xmp
IMG_02193.xmp
IMG_02194.xmp
IMG_02195.CR2
IMG_02195.xmp
As you can see the two in bold are orphans, while the CR2's were deleted during my culling of the bad shots but the Image Viewer doesn't delete the xmp file. Therefore I need a script to identify all files that do not have a cr2 version.
Script to find orphan xmp files
-
Steadyhands
- Posts: 24
- Joined: 13 Sep 2006 11:47
- Location: Brisbane, Australia
- Contact:
-
ale
- Posts: 127
- Joined: 19 Feb 2009 23:23
- Location: Italy
Re: Script to find orphan xmp files
I'm sorry you didn't receive answers yet, maybe as a starting point you can try something like this, but keep in mind I'm not expert like other users and I wrote this right now without much thinking and testing
Code: Select all
sortby;
selfilter "*.cr2|*.xmp";
$list = report("{Name}<crlf>", 1);
regexreplace $filtered, "$list", ".*\.cr2\r\n.*\.xmp\r\n", "";
replace $filtered, "$filtered", "<crlf>", "|";
selfilter "$filtered";
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: Script to find orphan xmp files
That's actually a pretty decent solution (much smaller and simpler than mine), and assuming you never have orphan cr2 files followed by orphan xmp files it should work fine for the OP.ale wrote:I'm sorry you didn't receive answers yet, maybe as a starting point you can try something like this, but keep in mind I'm not expert like other users and I wrote this right now without much thinking and testingCode: Select all
sortby; selfilter "*.cr2|*.xmp"; $list = report("{Name}<crlf>", 1); regexreplace $filtered, "$list", ".*\.cr2\r\n.*\.xmp\r\n", ""; replace $filtered, "$filtered", "<crlf>", "|"; selfilter "$filtered";
But it wouldn't work for instance here:
Code: Select all
A.cr2
A.xmp
B.cr2
C.cr2
D.xmp
E.xmpThis is a much more complicated solution which should work all of the time.. but assuming your data set never has orphan cr2 files, you'd be better off using ale's:
Code: Select all
"cr2 & xmp Pairs"
Global($typeA, $typeB);
$typeA = "xmp";
$typeB = "cr2";
Sub("_findOrphans");
"_findOrphans"
Global($typeA, $listA, $typeB, $listB);
//Generate lists for each type.
SelFilter("*.$typeA", "f", "Name");
$listA = GetInfo("SelectedItemsNames", ";");
RegExReplace($listA, $listA, "\.$typeA;", ";");
SelFilter("*.$typeB", "f", "Name");
$listB = GetInfo("SelectedItemsNames", ";");
RegExReplace($listB, $listB, "\.$typeB;", ";");
//Prune listA tokens.
Setting("AllowRecursion", 1);
Global($i);
$i = 1;
Sub("_pruneLoop");
//Prune listB tokens.
$temp = $listA;
$listA = $listB;
$listB = $temp;
$i = 1;
Sub("_pruneLoop");
Setting("AllowRecursion", "r");
//Select the orphan files.
RegexReplace($selListA, $listB, ";", ".$typeA;");
RegexReplace($selListB, $listA, ";", ".$typeB;");
RegexReplace($selectList, "$selListA$selListB", "^;|;$", "");
RegexReplace($selectList, "$selectList", ";+", ";");
SelFilter("$selectList", "f", "Name");
//Display a list of missing files.
RegexReplace($listA, $listA, ";", "<crlf>");
RegexReplace($listB, $listB, ";", "<crlf>");
Text("Missing $typeA file(s) for:<crlf>$listA<crlf><crlf>Missing $typeB file(s) for:<crlf>$listB",,,,"w","<crlf>");
//Look for listA tokens in listB, remove from both if found.
"_pruneLoop"
Global($listA, $listB, $i, $token);
$token = GetToken($listA, $i, ";");
End($token Like "",, 1);
StrPos($idx, $listB, $token);
Sub($idx >= 0 ? "_removeToken" : "_skip");
$i = $i + 1;
Sub("_pruneLoop");
//Remove this token from both lists; adjust i to avoid skipping a token.
"_removeToken"
Global($listA, $listB, $i, $token);
$i = $i - 1;
RegexReplace($listA, $listA, "$token;", "");
RegexReplace($listB, $listB, "$token;", "");
//Do nothing.
"_skip" ;
XYplorer Beta Club