#!/usr/bin/perl -w use strict; BEGIN { unshift @INC, '/usr/bin/lib' } use Image::ExifTool; print "Using ExifTool version $Image::ExifTool::VERSION\n"; @ARGV > 2 or die "Syntax: script TAG DIR FILE [FILE...]\n"; my $tag = shift; my $dstdir = shift; my $exifTool = new Image::ExifTool; my $moved = 0; my ($file, %foundValue); foreach $file (@ARGV) { my $info = $exifTool->ImageInfo($file, $tag); unless (%$info) { warn "$tag not found in $file\n"; next; } my ($val) = values %$info; if ($foundValue{$val}) { # duplicate value, so move to destination directory print "$tag is the same in $file as $foundValue{$val}\n"; my $dst = $file; $dst =~ s{.*/}{}; # remove directory name $dst = "$dstdir/$dst"; if (-e $dst) { warn "$dst already exists!\n"; } elsif (not rename($file, $dst)) { warn "Error moving $file to $dst\n"; } else { print " --> moved\n"; ++$moved; } } else { $foundValue{$val} = $file; # save first file with this value } } printf "%5d files processed\n", scalar(@ARGV); printf "%5d files moved\n", $moved; # end