http://qs321.pair.com?node_id=11120080

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.

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 (Archbishop) 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 (Bishop) 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.

      Dear Limbic~Region,

      I put a ".jpeg" and a ".jpg" dummy files in the '/' directory and your script didn't find either. I did this after running the script for a half hour without finding anything and I have lots of ".jpg" files on my Window 10 system, so I suspect the cygwin version "File::Find::Rule" may have a problem. I use the X windows environment on Win10 to connect to Linux systems.

      Regards...Ed

      "Well done is better than well said." - Benjamin Franklin

Re: Find Photos Taken During A Certain Time Range
by bliako (Monsignor) 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