Photograph file dates

Paul Lemmons paul at lemmons.name
Sat Jan 31 22:32:29 UTC 2009


Dotan Cohen wrote:
> 1) How can I change the dates of files? I know about the touch
> command, but I'd rather give her a GUI program. She has a few tens of
> files to change the dates of.
>
> 2) How can I see the date information in a jpeg? Is there a program
> that can use that information to set the date of a file as per the
> exif information?
>
> Thanks!
>   
Hello Dotan,

Here is a perl script that I wrote some time back that sends files to 
directories based on their dates and update the timestams on the file. I 
think I remember you being able to code in perl. This may or may not 
meet the need but I think it is close to what you are asking for. Take a 
look and let me know if you need any assistance modifying it.

I think "apt-get install libimage-info-perl" will get you all the parts 
you need to run the script.

-Paul

#!/usr/bin/perl -w
use Image::Info qw(image_info dim);

$testing      = 0;
$fromImageDir = "/home/paul/pics";
$toImageDir   = "/home/paul/newPics";

opendir(PICS,$fromImageDir) or die "Unable to open $fromImageDir:$!\n";
while ($fileName = readdir(PICS))
{
   if (-f "$fromImageDir/$fileName" and $fileName =~ /jpg$/i)
   {
      $info = image_info("$fromImageDir/$fileName");
      if ($error = $info->{error})
      {
         print "Can't parse image info for file: 
$fromImageDir/$fileName, Reason: $error\n";
      }
      else
      {
         if (defined($info->{'DateTimeOriginal'})   and
             $info->{'DateTimeOriginal'} !~ /^\s*$/ and
             $info->{'DateTimeOriginal'} !~ /^0000/)
         {
            $newDir = substr($info->{'DateTimeOriginal'},0,10);
            $newDir =~ s/:/-/g;

            $timestamp = $info->{'DateTimeOriginal'};
            $timestamp =~ s/[: ]//g;
            if (length($timestamp) == 14)
            {
               substr($timestamp,12,0)= '.';
            }

            print "$fileName: $newDir, Original Date: 
".$info->{'DateTimeOriginal'}."\n";
            if (!(-e "$toImageDir/$newDir"))
            {
               if ($testing)
               {
                  print "Would make the directory: $toImageDir/$newDir\n";
               }
               else
               {
                  mkdir("$toImageDir/$newDir",0755) or die "Unable to 
create directory: $toImageDir/$newDir: $!\n";
               }
            }

            if (-e "$toImageDir/$newDir/$fileName")
            {
               print "... already exists, skipping\n";
            }
            else
            {
               if ($testing)
               {
                  print "Would move file $fromImageDir/$fileName to 
$toImageDir/$newDir/$fileName\n";
                  print "Would set timestamp to: $timestamp\n";
               }
               else
               {
                  if 
(rename("$fromImageDir/$fileName","$toImageDir/$newDir/$fileName"))
                  {
                     `touch -t $timestamp $toImageDir/$newDir/$fileName`;
                     print "... moved successfully and timestamp updated\n";
                  }
                  else
                  {
                     print "... Unable to move $fileName from 
$fromImageDir to $toImageDir/$newDir: $!\n";
                  }
               }
            }
         }
         else
         {
            print "No date found in picture exif data for picture: 
$fileName\n";
         }
      }
   }
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3296 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://lists.ubuntu.com/archives/kubuntu-users/attachments/20090131/1232afad/attachment.bin>


More information about the kubuntu-users mailing list