Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: date created in exiftool

by flieckster (Scribe)
on Dec 04, 2018 at 15:17 UTC ( #1226728=note: print w/replies, xml ) Need Help??


in reply to Re: date created in exiftool
in thread date created in exiftool

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"; # }; } # }

Replies are listed 'Best First'.
Re^3: date created in exiftool
by hippo (Bishop) on Dec 04, 2018 at 16:28 UTC

    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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1226728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2022-05-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?