Help searching for files using EXIF criteria
Posted: 06 Sep 2019 14:39
Would anyone like to give me hand writing a script that would search within an image file's EXIF data, if this is possible? PM if you can help!

Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Code: Select all
$times = input("Enter exposure time(s)", "Separate them by comma!", "1/20, 1/50, 1/80", , , 600, 400);
if (!$times) { status "No exposure times given, aborted!", "8B4513", "stop"; end true; }
$times = "(" . regexreplace($times, ",[ ]*", "|") . ")";
$files = quicksearch("/types={:Image} /f", , , "s");
$result = "";
foreach($file, $files, <crlf>, "e") {
$time = property("#image.exposuretime", $file);
if (!$time) { continue; }
$time = regexreplace($time, "[ ][s]$");
if (regexmatches($times, $time)) { $result .= $file . <crlf>; }
}
if ($result) { tab("new"); paperfolder("Exposure_Times", $result, , "nl"); end true; }
status "No image file(s) found, that match any of these times...", "8B4513", "stop";
quicksearch("/types={:Image} /f", , , "s");{:Image} is a container for the following file types:
Code: Select all
text formatlist(get("genericfiletype", "{:Image}"), "s", <crlf>);Code: Select all
*.arw
*.bmp
*.clip
*.cpt
*.cr2
*.crw
*.cur
*.dcr
*.dds
*.dib
*.dng
*.emf
*.erf
*.exr
*.fff
*.gif
*.hdr
*.ico
*.jfif
*.jpe
*.jpeg
*.jpg
*.lip
*.mef
*.mrw
*.nef
*.nrw
*.orf
*.pef
*.pic
*.pict
*.png
*.psb
*.psd
*.raf
*.raw
*.rle
*.rw2
*.rwl
*.sr2
*.srf
*.srw
*.tga
*.tif
*.tiff
*.tpic
*.webp
*.wmf
*.x3f
Code: Select all
// .jpg / .rw2 use Exif.Photo.ExposureTime
// .dng use Exif.Image.ExposureTime
// If the time contains a dot, it needs to be converted...
// $time = 0.00107169 -> 1 / $time;
$exiv2 = "D:\Tools\@Command Line Tools\exiv2\exiv2.exe";
$exiv2Options = "-K Exif.Photo.ExposureTime −K Exif.Image.ExposureTime -Pt";
$times = input("Enter exposure time(s)", "Separate them by comma!", "1/20, 1/50, 1/80", , , 600, 400);
if (!$times) { status "No exposure times given, aborted!", "8B4513", "stop"; end true; }
$times = "(" . regexreplace($times, ",[ ]*", "|") . ")";
$files = quicksearch("/types={:Image} /f", , , "s");
$log = ""; $logTime = ""; $logNoTime = ""; $result = "";
foreach($file, $files, <crlf>, "e") {
status "Processing: " . gpc($file, "file"), , "progress";
$ext = gpc($file, "ext");
// XYplorer can only? get the exif data from .jpg files
if ($ext LikeI "jpg") {
$time = property("#image.exposuretime", $file);
$time = regexreplace($time, "[ ][s]$");
// exiv2 alternative...
} else {
$time = gettoken(runret("""$exiv2"" $exiv2Options ""$file"""), 1, <crlf>);
sysdebug $time;
$time = regexreplace($time, "[ ][s]$");
// Convert format if necessary
if (strpos($time, ".") != -1) {
$time = "1/" . regexreplace((1 / eval($time)), "(\.|,)\d*?$");
}
}
if (!$time) { $logNoTime .= $file . <crlf>; continue; }
$logTime .= $file . " <--> Time: " . $time . <crlf>;
if (regexmatches($times, $time)) { $result .= $file . <crlf>; }
}
if ($result) {
tab("new");
paperfolder("Exposure_Times", $result, , "nl");
$logTimeHeader = "File(s) with exposure time";
$logNoTimeHeader = "File(s) WITHOUT exposure time";
if ($logTime) { $log .= $logTimeHeader . <crlf> . strrepeat("=", strlen($logTimeHeader)) . <crlf> . $logTime . <crlf 2>; }
if ($logNoTime) { $log .= $logNoTimeHeader . <crlf> . strrepeat("=", strlen($logNoTimeHeader)) . <crlf> . $logNoTime . <crlf 2>; }
copytext $log;
} else {
status "No image file(s) found, that match any of these times...", "8B4513", "stop";
}
XY looks for EXIF data in the following file types:DanielMcKinney wrote: ↑06 Sep 2019 17:37 Excellent! Thanks. But can it search for image files other than jpg? I am also working with tif, dng, and rw2 files, all of which should have EXIF data.