Having trouble setting a time zone offset during file renaming

Started by George Jardine, May 08, 2014, 06:48:16 PM

Previous topic - Next topic

George Jardine

I'm copying CR2 files from a camera card to a destination in my photo library in a bash script (mac). This string seems to be working great for my purposes:

exiftool -r -P "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH

... giving me filenames that look like this:  20140508-205107-MDT-5DM30004.CR2

My trouble comes when I want to shift the time info in the new filenames, but do not want to change the raw files at all. If my camera is set to GMT, and I'm shooting in Denver (while it's MDT), I want the filenames to reflect the local time, but I do not want the GMT-based timestamps in the file to be altered.

I've tried several variations on this...

exiftool -r -P "-FileName<DateTimeOriginal-=6" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH

exiftool -r -P "-FileName<DateTimeOriginal-=0600" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH

... and so forth, but don't seem to be getting anywhere.

Sorry for the beginner's question. Any guidance someone can provide would be most appreciated.


Phil Harvey

Hi George,

You are having trouble because ExifTool doesn't have the ability to do this.

Either you need to make a user-defined tag with a shifted date/time (which is tricky and you would have to change the definition to change the amount of shift), or you can go through some intermediate file, and use 3 commands, like this:

exiftool -r -o "$TEMPFOLDER/%f.xmp" -datetimeoriginal $CAMERACARDPATH

exiftool $TEMPFOLDER -datetimeoriginal-=6

exiftool -r -P -tagsfromfile "$TEMPFOLDER/%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH


I think this should work, but I didn't test it to be sure I didn't make a mistake.

- Phil

Edit: The -globalTimeShift option provides a better solution... see my later post
...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 ($).

George Jardine

Thanks, Phil. Your suggestion using tagsfromfile looks interesting. I'll try that.

Appreciate your help,
George


George Jardine

Phil, your suggested command strings work pretty well. The only snag is that I have occasionally run into a Canon camera card that has multiple image folders on it. When this happens it usually means you'll have duplicate filenames across the folders, which causes collisions as EXIFTool is trying to write the XMP files.

I've solved it by looping through the folders on the card (100EOS5D, 101EOS5D, 102EOS5D, etc.), changing the filenames during the copy, and then clearing out the contents of the TEMPFOLDER at the end of each loop.

Admittedly, this will only happen infrequently, but I was alerted to it as a potential problem the other day. Just a few frames after my camera rolled over from 9999 to 0001 it crashed for some reason. I had to take the battery out to revive it and that (or the crash) reset the counter, just as manually resetting the counter or creating a new folder on the camera would do.

Anyway, looping through the folders works. Thanks again for the help.

Phil Harvey

An alternative is to create the same directory structure for the temporary files, something like this:

1. cd $CAMERACARDPATH

2. exiftool -r -o "$TEMPFOLDER/%d%f.xmp" -datetimeoriginal .

3. exiftool -r $TEMPFOLDER -datetimeoriginal-=6

4. exiftool -r -P -tagsfromfile "$TEMPFOLDER/%d%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" .

Additionally, you could add "_%e" ("$TEMPFOLDER/%d%f_%e.xmp") to the temporary file names to handle the case with same-named files with different extensions in the same directory.

- Phil

Edit: Forgot a -r in command 3.
...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 ($).

George Jardine

> Edit: Forgot a -r in command 3.


Caught that.  :-)

Now you've given me more work to do. Many thanks for your helpful suggestions.

G.

George Jardine

I'm having trouble finding documentation on how I can set a specific extension using "_%e" option.

When copying files into another folder, in the case of a filename collision I would like to change the default "-10" or "-11" extension that is added to the incoming files.

Any pointers would be much appreciated.

George

Phil Harvey

Hi George,

This is explained in detail in the -w option section of the application documentation.

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

George Jardine

Well, I guess I'm dense enough that I probably need an example.

It seems the -w option is to write or overwrite the output text files (in this case XMP), if I'm reading that correctly. In any case, once I'm finished with a successful copy with rename, I delete the temp XMP files. And it's during a subsequent copy with rename into the same destination, that I need to worry about filename collisions. (For those cases where I might add new photos to a card that I've already imported, I want exiftool to skip those that already exist, if possible.)

Does this make sense? Thanks again from an impaired, amateur coder.


Phil Harvey

Yes, this makes sense.  You won't be using the -w option, but the file name formatting is the same for all ExifTool features.

I guess I'm not really clear on what you're doing now and how you want to change it, so I can't give you a specific example...  I don't know what you are talking about when you mention "-01" and "-11" extensions.

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

George Jardine

#10
The code as you suggested is working well:

   cd /Volumes/EOS_DIGITAL

   exiftool -r -o "$TEMPFOLDER/%d%f.xmp" -datetimeoriginal .

   exiftool -r $TEMPFOLDER -datetimeoriginal$TZOFFSET

   exiftool -r -P -tagsfromfile "$TEMPFOLDER/%d%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S$TZOFFSETFORFILENAMES-%%f.%%e" -o "$DESTINATIONFOLDER" .

This gives me file names in the destination that look like this:

20140421-134855-0600-5DM30058.CR2
20140421-135122-0600-5DM30059.CR2
20140421-135131-0600-5DM30060.CR2

And then I am deleting the entire temp folder for that copy and renaming session. All of this works great unless I run the script on the same card twice, or if I don't reformat the card, add photos to it, and then try to run the script on that card to just copy the new images from it. So I either need a way to have exiftool skip files that already exist in the destination with the same name, or allow duplication with an additional extension, giving file names that look like this:

20140421-134855-0600-5DM30058.CR2
20140421-134855-0600-5DM30058-2.CR2
20140421-134855-0600-5DM30059.CR2
20140421-134855-0600-5DM30059-2.CR2
20140421-135122-0600-5DM30060.CR2
20140421-135131-0600-5DM30060-2.CR2

Thanks for any pointers you can provide.

George

Phil Harvey

Hi George,

Quote from: George Jardine on May 14, 2014, 09:15:48 AM
So I either need a way to have exiftool skip files that already exist in the destination with the same name, or allow duplication with an additional extension.

Currently, it will skip files that already exist (giving appropriate error messages).

To duplicate the files as you indicated, add a "%-c" in step 4:

exiftool -r -P -tagsfromfile "$TEMPFOLDER/%d%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f%%-c.%%e" -o "$DESTINATIONFOLDER" .

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

George Jardine


George Jardine

Phil, now I'm tweaking things, and I'm finding a very weird anomaly. I'm absolutely sure this is not your problem, but I wondered if you would venture an opinion on what's going on.

When I run the scripts using either EXIFTool (as we've been talking about in this thread) or using cp -Rpv to copy the files on my iMac, the modification dates are never updated, as desired.

But when I run the very same scripts (I've tested copies performed by both cp and EXIFTool) on my MBP laptop, I find 20 or 30% of the new copies DO have updated modification files. And of course it's never the same files. Sometimes it's just a handful, other times dozens (out of 170 in this test). In these tests, I'm using the same camera card, same source photos, same card reader, same cable, everything. Both Macs are running 10.8.5.

So it seems pretty strange that both copy methods work as expected on one machine, but on the laptop, there are always at least a few random files copied with updated modification times. (Always modified to the exact moment of the copy.)

Is this my worst nightmare? (Bad hardware?) Any thoughts on what might be causing this?

Thanks again for your help,
George

Phil Harvey

Hi George,

This may be a bug in OS X.  I have seen problems before with the filesystem modification time not getting set correctly.  I have tried to find a work-around, but couldn't.  One user has submitted a bug report to Apple, but I haven't heard back.  See this thread for details.

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