Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Find Photos Taken During A Certain Time Range

by Limbic~Region (Chancellor)
on Jul 30, 2020 at 18:51 UTC ( #11120080=perlquestion: print w/replies, xml ) Need Help??

Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All,
I am looking for a little help with a File::Find::Rule and Image::ExifTool script. My environment is Windows but I only have Perl available via Cygwin. I have a bunch of hard drives in this machine collected over the years so a manual search has proven to be untenable.
  • Search all files with a .jpg or .jpeg extension (case insensitive)
  • Once found, check to see when the photo was taken.
  • If taken in 2015, give me the path to the file and the date the picture was taken

I haven't really coded in years so while this once seemed like a trivial task, I am having issues getting the expected results.

#!/usr/bin/perl use strict; use warnings; use File::Find::Rule; use Image::ExifTool qw(:Public); my $tool = Image::ExifTool->new(); for my $file (File::Find::Rule->file()->name( qr/\.(jpeg|jpg)$/i)->in( +'/')) { my $info = ImageInfo($file, 'DateTimeOriginal'); my $date = $info->{DateTimeOriginal}; next if ! $date || $date !~ /^2015/; print "$file\t$date\n"; }

When I tried it in my home directory as a test, it did exactly what I expected but when I changed '.' to '/' it started generating every file on the system (directories, text files, etc.) without the date.

Cheers - L~R

Replies are listed 'Best First'.
Re: Find Photos Taken During A Certain Time Range
by haukex (Bishop) on Jul 30, 2020 at 19:18 UTC
    When I tried it in my home directory as a test, it did exactly what I expected but when I changed '.' to '/' it started generating every file on the system (directories, text files, etc.) without the date.

    That seems strange; I don't have Cygwin but I can't reproduce the issue on Linux, so it could maybe have something to do with the interaction of Cygwin and File::Find::Rule. Is the code you showed here exactly what you're running? Unless another Monk with Cygwin can reproduce the issue and find out what's wrong, you may need to look into it yourself. As a start, perhaps reduce your code even further, since it doesn't sound like it has to do with Image::ExifTool. The following seems to work fine on my system:

    use warnings; use strict; use File::Find::Rule; my $rule = File::Find::Rule->file->name(qr/\.jpe?g$/i)->start('/'); while ( defined( my $file = $rule->match ) ) { print "$file\n"; }
Re: Find Photos Taken During A Certain Time Range
by Fletch (Chancellor) on Jul 30, 2020 at 19:37 UTC

    Marginal cygwin experience, but maybe explicitly iterate over the drives mapped using something like this?

    for my $drive (glob(q{/cygdrive/*})) { for my $file ( File::...as before...->in( $drive ) ) { ## as before } }

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Find Photos Taken During A Certain Time Range
by bliako (Prior) on Jul 30, 2020 at 19:23 UTC

    What you posted seems OK to me for searching from the root dir (i.e. ->in('/')). If you changed to this File::Find::Rule->file()->name( qr/\/(jpeg|jpg)$/i)->in('/') then it should start looking from '/' but it should not match anything interesting.

    Edit: in linux

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11120080]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2020-10-31 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?