in reply to date created in exiftool

flieckster:

Since line 42 is printing the value in $info->{$_} for key $_, it simply means that the key has no value for it. It may be possible that the ImageTool call is failing because it can't find the file you're specifying. Since you're changing directories between fetching the filenames and processing them, it could be that you just need to ensure you're providing a correct relative or absolute path to the file.

I'd also suggest checking out what error conditions you can expect from Image::ExifTool to see if it's working properly. (I just tried to review the docs for it, but cpan.org is feeding me blank pages at the moment when I give it a search term.)

Another thought: some images might not have values for the tags you're checking, so you might want to check the existance of the tag before printing anything:

foreach (@tags) { if (! exists $info->{$_}) { print "file $file doesn't have tag $_\n"; } elsif (! defined $info->{$_}) { print "file $file has tag $_, but it has no value\n"; } else { print "$info->{$_}\t"; } }

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: date created in exiftool
by flieckster (Scribe) on Dec 04, 2018 at 15:17 UTC
    Hi Roboticus, thanks for the snippet. i re-wrote the code adding your added variables, and it seems to be working now, but also worked with my original code now. i'm not sure why. I can get this to print out the date's in the format i want with "$info->{$_}" but starting on line 73 where i want to use that date output, is where it fails. with this error.
    prefix TUMI style 1174451041 view tag 1174451041 was created Use of uninitialized value $_ in hash element at /var/folders/ty/jy84g +mxs4f7c_n0bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled text.pl line + 73. Use of uninitialized value in string at /var/folders/ty/jy84gmxs4f7c_n +0bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled text.pl line 73. Use of uninitialized value $_ in hash element at /var/folders/ty/jy84g +mxs4f7c_n0bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled text.pl line + 79. Use of uninitialized value in mkdir at /var/folders/ty/jy84gmxs4f7c_n0 +bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled text.pl line 79. Use of uninitialized value $_ in hash element at /var/folders/ty/jy84g +mxs4f7c_n0bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled text.pl line + 80. Use of uninitialized value in scalar assignment at /System/Library/Per +l/5.18/File/Copy.pm line 110. Use of uninitialized value $to in string eq at /System/Library/Perl/5. +18/File/Copy.pm line 102. Use of uninitialized value $to in -d at /System/Library/Perl/5.18/File +/Copy.pm line 134. Use of uninitialized value $to in stat at /System/Library/Perl/5.18/Fi +le/Copy.pm line 142. Use of uninitialized value $to in open at /System/Library/Perl/5.18/Fi +le/Copy.pm line 234. Use of uninitialized value $_ in hash element at /var/folders/ty/jy84g +mxs4f7c_n0bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled text.pl line + 80. Use of uninitialized value in concatenation (.) or string at /var/fold +ers/ty/jy84gmxs4f7c_n0bhfhvs6t40000gq/T/TextWranglerRunTemp-untitled +text.pl line 80.
    #!/usr/bin/perl -w use Net::FTP; use File::Copy; use File::Basename; use POSIX qw(strftime); BEGIN { unshift @INC, '/usr/bin/lib' } use Image::ExifTool 'ImageInfo'; print "#################################\n"; print "#################################\n"; print "#################################\n"; print "#################################\n"; print "#################################\n"; my $sort = "/Users/flieckb/Desktop/psds/"; my $wpf = "/Users/flieckb/Desktop/sort/"; chdir( $sort ) or warn "Cant chdir to $sort $!"; my(@sort_list) = glob "*.psd"; my $sortlist = @sort_list; my $prefix; my $style; my $view; my $exifTool = new Image::ExifTool; foreach my $file (@sort_list){ my @tags = qw(DateTimeOriginal); $exifTool->Options(Duplicates => 0, DateFormat => '%m-%d-%Y'); my $info = $exifTool->ImageInfo($file, \@tags); foreach (@tags) { print "$info->{$_}\t"; } print "\n"; # # foreach (@tags) { # if (! exists $info->{$_}) { # print "file $file doesn't have tag $_\n"; # } # elsif (! defined $info->{$_}) { # print "file $file has tag $_, but it has no value\n"; # } # else { # print "$info->{$_}\n"; # } # if ($file =~qr/\A([^_]+)-([^_]+)(?:_([^_]+))?\.([^\.]+)\z/) { # $prefix = $1; # $style = $2; # $view = $3; # # print "prefix $prefix\n"; # print "style $style\n"; # print "view $view\n"; # # my $movelist = "$sort$file"; # if (-d "$style") { # chdir ($style) and print "$style already exsits\n"; # } # else # { # mkdir($style, 0777)and print "$style was created\n"; # chdir ($style); # } # ## # if (-d "$info->{$_}") { # print "$info->{$_} already exsits\n"; # copy ($movelist, $info->{$_})or warn print "Copy $info->{$_} Failed: + $!\n"; # } # else # { # mkdir($info->{$_}, 0777); # copy ($movelist, $info->{$_})or warn print "Copy $info->{$_} Failed: + $!\n"; # } # chdir ($wpf); # } # else # { # print "did not match expression = $file\n"; # }; } # }

      There's an awful lot in your script which doesn't need to be there. Here's a stripped down version with none of the unnecessary modules, no commented-out code, indented loops and no BEGIN blocks. Oh, and it has strict as should every script you ever write.

      #!/usr/bin/env perl use strict; use warnings; use Image::ExifTool 'ImageInfo'; print "#################################\n"; my $sort = "/tmp/"; chdir $sort or die "Cant chdir to $sort $!"; my @sort_list = glob "*.jpeg"; my $exifTool = Image::ExifTool->new; my @tags = qw(DateTimeOriginal); foreach my $file (@sort_list) { $exifTool->Options(Duplicates => 0, DateFormat => '%m-%d-%Y'); my $info = $exifTool->ImageInfo($file, \@tags); foreach (@tags) { print "$file $_: $info->{$_}\t" if exists $info->{$_}; } print "\n"; }

      This works fine for a collection of jpegs I've put in /tmp for testing (I have no use for .psd files). It produces no errors and no warnings and a nice list of original dates in day-in-the-middle format (your choice, not mine).