in reply to Getting file attributes/properties using Win32 OLE

If you're working with camera-produced JPEG files, you might consider using the Image::MetaData::JPEG module to retrieve the picture's timestamp directly from the JPEG metadata.
  • Comment on Re: Getting file attributes/properties using Win32 OLE

Replies are listed 'Best First'.
Re^2: Getting file attributes/properties using Win32 OLE
by odog502 (Initiate) on Jan 12, 2010 at 03:04 UTC

    Thanks for the suggestion Ollie. You helped me find the solution to the problem. I didn't use Image::MetaData::JPEG but I did use one similar to it, Image::ExifTool::Exif. Your suggestion got me looking for the right thing though thanks. I downloaded the module from CPAN, then I was able to do what I set out to accomplish. Heres the code I wrote for anyone that is interested:

    #!/usr/local/bin/perl # # PicRenamer.pl # script to rename pics and videos based on the date # in the following format "YYYY-MM-DD_HHmmSS_Event.JPG" # # Written by: odog502 # backup all your files before trying this!!! Im not responsible # for any missuse of this script # $dir = 0; $event; $property; $filetype; print 'Enter location of files to be renamed (ex. C:/test): '; chomp($dir = <STDIN>); print 'Enter the name of event that describes these pictures(no sp +aces): '; chomp($event = <STDIN>); print 'Enter the exif property that contains the date(eg Date/Time + Original): '; chomp($property = <STDIN>); # examples "File Modification Date/Time", "Create Date", "Date/Tim +e Original" print 'Enter the extension of the filetype you want modify(e.g. \' +jpg\'): '; chomp($filetype = <STDIN>); chdir ("$dir"); # # gets appropriate files and sorts them by file name # @files = <*.$filetype>; @files = sort {$a cmp $b} @files; # # Go through each filename and use exif to get its properties. # Loop through each property until you find the one with the date # Rename the file to the date found in the property, add the custom # "event" name to the end. # $i = 0; until ($i > $#files) { print "working on file: $i $files[$i]\n"; open (FILEPROP, "C:\\Image-ExifTool-8.00\\exiftool.pl \"$dir\\ +$files[$i]\" |") or die $!; while (<FILEPROP>){ chomp; if ( $_ =~ /$property\s*: (\d{4}):(\d{2}):(\d{2}) (\d{2}): +(\d{2}):(\d{2})/){ print "Changing to: $1-$2-$3_$4$5$6_$event.$filetype\n +"; rename "$files[$i]", "$1-$2-$3_$4$5$6_$event.$filetype +"; } $j++; } close FILEPROP; $i++; }