Using exiftool to import photos from memory-cards

Started by Andreas Spindler, February 13, 2011, 09:32:52 AM

Previous topic - Next topic

Andreas Spindler

A few month ago I posted a short script to import files from memory cards into a preview-directory:

   function import() {
               local dcimdir="$1" previewdir="${2:-.}"
               exiftool -r -P '-FileName<DateTimeOriginal' \
                   -o dummy/ \
                   -d "$previewdir/%Y-%m-%d/%%f%%-c.%%le" \
                   "$dcimdir/"
   }

The case is that Exiftool has no explicit copy-option. Without the dummy-directory files would be moved away from the card.

In his response Phil explained that -d just specifies how the tag-to-filename conversion is done. If you then wonder where the %Y-%m-%d part comes from, since only the FileName tag is set, not the Directory tag, read this https://exiftool.org/filename.html. There the "-o dummy/" idiom is explained. From this text one may guess that the dummy-directory is never created. This is not exactly true.

In December 2010 I bought a new camera and made some photos without having set its clock. The EXIF:DateTimeOriginal tag contains just zeroes for these photos; at least this is what XnView says. Exiftool prints

Warning: No writable tags found

Then Exiftool creates the dummy-directory and copies all photos without shooting time there. The filename was not changed; in particular it ignored my -d spec.  The rest of the photos on the card - made with a correct clock setting - are copied to the directory specified with -d. I then found the dummy-directory rather by accident, after I already counted my early photos for lost.  :o

There are maybe good reasons for these behaviors.
Nevertheless my feeling now is that there's no straigt way to "pursade" Exiftool to copy files from a to b or fail.

For the moment I upgraded -o dummy/ into -o "$previewdir/".
But I suppose Exiftool should have copied the photos into 0000-00-00/ subdirectories, rather than disposing files under two different file- and directory-patterns.  ???

Phil Harvey

You could add -if '$dateTimeOriginal' to the command to only process images containing the DateTImeOriginal tag.

Otherwise, you are correct, the images would be copied to the dummy directory.

An alternative would be to add '-filename<filemodifydate' before setting filename from DateTimeOriginal.  Since FileModifyDate always exists, then it would be used for files where DateTimeOriginal is missing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Andreas Spindler

Thanks for the quick answer!
So

   function import() {
       local dcimdir="$1" previewdir="${2:-.}"
       exiftool -r -P -v0 \
           '-FileName<FileModifyDate' \
           '-FileName<DateTimeOriginal' \
           -o dummy/ \
           -d "$previewdir/%Y-%m-%d/%%f%%-c.%%le" \
           "$dcimdir/"
   }

should be the safest way of copying files, i.e. the dummy-directory is never used?

It's quite simple. Sometimes you miss the wood for the trees.  ::)

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).