ExifTool Forum

ExifTool => Newbies => Topic started by: simonmason on March 27, 2013, 09:14:16 PM

Title: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 27, 2013, 09:14:16 PM
I am trying to copy all images in a directory tree to a new directory tree created using directories named for date.  Here is the command I am trying:

exiftool -d /DIRNEW/%Y-%m-%d "-directory<datetimeoriginal" -r /DIROLD

The directory contains mostly jpg files.

After running I get a directory called "m-d" and all of the files are in this directory.  What I was expecting was directories named YYYY-MM-DD and files in each one.
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Tarn on March 28, 2013, 05:06:12 AM
Hi Simonmason,

    As you typed it, that command works for me. I changed "DIRNEW" to "TEST" and it put a directory named YYYY-mm-dd into my Test directory and move the files, no problem. What I don't understand is that you don't have the "$" sign in front of "datetimeoriginal" and it still worked. Hmmm.

   My question is: did you type this at the command prompt, or are you running it from a batch file? Your getting a directory called "m-d" means that the "%" characters are not being honored. This happens in a batch file, where you need to escape the "%" character, with another "%". -d /DIRNEW/%%Y-%%m-%%d instead of -d /DIRNEW/%Y-%m-%d.

    Second question is: Are you moving, or copying the files? If you write to the Directory tag, you move the files, not copy them. You would have to do something like using the -o option to write the files to the new directory. I'd love to give you an example but I got my butt whipped trying that tonight. So, I'm going to let it rest for a day and go back at it.

   Maybe Phil, or someone else who is a little better versed at this, than I am, will jump in and correct me, or fill in the parts I left out.
Hope this helps.
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 28, 2013, 07:18:19 AM
Hi Simon,

I think Tarn probably hit on the solution.  If you are running from a BAT file you need to double all of the "%" characters. 

To copy the files, add "-o dummy" to the command.  See this page (https://exiftool.org/filename.html) for details.

- Phil
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 28, 2013, 06:55:49 PM
Ok, I made the updates to the batch file - thanks for pointing out the %% needed.  It appears that a lot of files are failing with the error:

Warning: No writable tags set from directory/filename.

I went into the directory and ran exiftool on the file and the output is below.  It looks like it should work?  Am I missing something else?  Thanks.


ExifTool Version Number         : 9.24
File Name                       : 2011-11-22 at 14.51.33.jpg
Directory                       : .
File Size                       : 1952 kB
File Modification Date/Time     : 2011:11:27 13:58:43-05:00
File Access Date/Time           : 2013:03:27 21:06:13-04:00
File Creation Date/Time         : 2013:03:27 21:06:13-04:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Camera Plus
Orientation                     : Rotate 90 CW
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/16
F Number                        : 2.4
Exposure Program                : Program AE
ISO                             : 500
Exif Version                    : 0221
Components Configuration        : -, -, -, Y
Shutter Speed Value             : 1/16
Aperture Value                  : 2.4
Brightness Value                : -0.5142644505
Metering Mode                   : Multi-segment
Flash                           : Auto, Fired
Focal Length                    : 4.3 mm
Subject Area                    : 1631 1223 881 881
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 3264
Exif Image Height               : 2448
Sensing Method                  : One-chip color area
Exposure Mode                   : Auto
White Balance                   : Auto
Focal Length In 35mm Format     : 35 mm
Scene Capture Type              : Standard
Sharpness                       : Normal
Compression                     : JPEG (old-style)
Thumbnail Offset                : 570
Thumbnail Length                : 10751
Image Width                     : 3264
Image Height                    : 2448
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.4
Image Size                      : 3264x2448
Scale Factor To 35 mm Equivalent: 8.2
Shutter Speed                   : 1/16
Thumbnail Image                 : (Binary data 10751 bytes, use -b option to extract)
Circle Of Confusion             : 0.004 mm
Field Of View                   : 54.4 deg
Focal Length                    : 4.3 mm (35 mm equivalent: 35.0 mm)
Hyperfocal Distance             : 2.08 m
Light Value                     : 4.2
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 29, 2013, 07:15:56 AM
Your command relies on the existence of the DateTimeOriginal tag.

- Phil
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 29, 2013, 08:03:25 AM
I see.  So some of the files don't have this tag.  I found the following command:

exiftool '-EXIF:DateTimeOriginal<EXIF:CreateDate' picture.jpg

If I run this on the files that don't have the DateTimeOriginal tag then it should create it based on the File Creation tag?  Is there a way to have this command recursively check a directory structure and re-tag all files that exist?  Thanks.
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 29, 2013, 02:46:34 PM
Yes, of course there is a way to do this.  But I don't know what you mean by re-tag, so I can't be more specific.

- Phil
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 29, 2013, 03:56:27 PM
I am trying to process about 4000 files using the -directory<datetimeoriginal option and it appears that some of them don't have the DateTimeOriginal tag.  So I thought I could run the following command:

exiftool '-EXIF:DateTimeOriginal<EXIF:CreateDate' picture.jpg

on the files to create the Creation Date tag.  My assumption is that this will then insert the tag in the file needed to run the first command in order to complete my directory sorting.  My question - is the command the right one to do this?  And also, how could I run it on an entire directory tree and have it update all of the files?  Thanks.
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 29, 2013, 08:03:47 PM
Sorry.  I was being dense when I read your previous post.  You can do this on an entire directory tree by specifying a directory name instead of a file name and adding -r to recurse into subdirectories.   If you must do this I would add -if "not $datetimeoriginal" to only update the ones that don't have this information.

However, maybe it is easier just to use both "-directory<datetimeoriginal" and "-directory<createdate" in your original command to handle both cases.

- Phil

Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 29, 2013, 08:51:23 PM
So, woudl I use:

exiftool -d /DIRNEW/%Y-%m-%d "-directory<datetimeoriginal" "-directory<createdate" -r /DIROLD
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 29, 2013, 09:32:56 PM
exactly

- Phil
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 30, 2013, 09:40:21 AM
I am still having some issues here.  I tried running the following command:

exiftool -d DIRNEW/%%Y-%%m-%%d "-directory<datetimeoriginal" "-directory<createdate" -r DIROLD

This produced the same results as not including the "-directory<createdate".  All files with a Original Date/Time were processed and all others failed.  My intention was that it would look for first Original Date/Time and if not found use the Creation Date to process the files?

I also tried another approach, attempting to pre-process the files with the following command:

exiftool -if 'not $datetimeoriginal' '-EXIF:DateTimeOriginal<EXIF:CreateDate' -r DIR

But this didn't work either because exiftool keeps reporting that it cannot find any files.  I assumed that -r DIR would tell it to look for all supported files in the directory structure.

Also, one other quick question - I am confused as to the use of single or double quotes/inverted commas in commands.  It seems that they are interchangeable but perhaps this is causing some of my problems?  Thanks for your help.
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 30, 2013, 10:51:12 AM
I thought you were talking about the EXIF CreateDate, but apparently not.  Use "exiftool -a -s -time:all" on a file that didn't work to see what other date/time tags are available, and choose one of those instead.

Your other command didn't work because you need double quotes (not single quotes) around arguments in Windows.

- Phil
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: simonmason on March 31, 2013, 09:56:03 AM
I think that my issue is that I am confusing EXIF for metadata. It looks like the dates are inconsistently sprinkled between several fields.I will randomly check the files to see what the best approach is.

One other question. There are a bunch of QuickTime movies (.mov) in there. I see that exiftool supports read on this file type. When I run the directory command (above) to sort into directories by date the .mov files do not get moved.  Although I am not writing to these files - just moving into a new directory structure - I assume that they are not moved Because writing is not supported?  Thanks.
Title: Re: Whats wrong with this syntax - trying to create directories by date
Post by: Phil Harvey on March 31, 2013, 10:37:20 AM
I suggest this command to show all the dates:

exiftool -time:all -a -G1 -s -r DIR

By default, ExifTool only processes writable files when writing.  But you can use the -ext option to specify the extensions you want processed.

- Phil