ExifTool Forum

ExifTool => Newbies => Topic started by: Moonbase59 on April 11, 2022, 09:26:48 AM

Title: How to copy images to specific (absolute path) folder?
Post by: Moonbase59 on April 11, 2022, 09:26:48 AM
Using exiftool 12.30-1 on Manjaro Linux, I'm trying to copy images from arbitrary folders into my /home/matthias/Bilder folder, using a YYYY/YYYY-MM/YYYY-MM-DD/YYYYMMDD-hhmmss.ext scheme.

For some reason, this doesn't work out—the best I could get is subfolders inside my current folder.

Starting out in the /home/matthias/Bilder/Testbilder/ folder, I tried these commands:


exiftool -P -o ~/Bilder/ -d '%Y/%Y-%m/%Y-%m-%d/%Y%m%d-%H%M%S' '-FileName<${MWG:CreateDate}-${Model}%-c.%le' 20080206-035955-EX-Z80.jpg
    1 directories created
    1 image files copied

(creates 2008/2008-02/2008-02-06/20080206-035955-EX-Z80.jpg inside the current folder),


exiftool -P -o -d '/home/matthias/Bilder/%Y/%Y-%m/%Y-%m-%d/%Y%m%d-%H%M%S' '-FileName<${MWG:CreateDate}-${Model}%-c.%le' 20080206-035955-EX-Z80.jpg
Warning: Error opening file - /home/matthias/Bilder/%Y/%Y-%m/%Y-%m-%d/%Y%m%d-%H%M%S
Error: Error opening file - /home/matthias/Bilder/%Y/%Y-%m/%Y-%m-%d/%Y%m%d-%H%M%S
    0 image files updated
    1 image files copied
    1 files weren't updated due to errors

(creates a file 2008:02:06 03:59:55-EX-Z80.jpg inside the current folder).

Where and how should I specify an absolute path for the images to be copied or moved to?
Title: Re: How to copy images to specific (absolute path) folder?
Post by: StarGeek on April 11, 2022, 11:15:11 AM
The clue is in the error, exiftool is trying to create a file "%Y-%m-%d/%Y%m%d-%H%M%S".  That means it's not reading that as a date string.

The reason for that is that you are using the -o (-out) option (https://exiftool.org/exiftool_pod.html#o-OUTFILE-or-FMT--out) without the OUTFILE or FMT parameter, so it ends up using the -d as that parameter.

Since you are writing to the Filename pseudo-tag, then this line in the -o docs is important (emphasis mine)
     When writing only FileName and/or Directory "pseudo" tags, -o causes the file to be copied instead of moved, but directories specified for either of these tags take precedence over that specified by the -o option.

You still need to include a directory name as the second -o parameter, but it will be ignored.  The most common thing to do here is to use a dot . for the current directory, since that's nice and short.

The -o option can be tricky.  Examples #5, #9, #10, and #11 on the Writing "FileName" and "Directory" tags page (https://exiftool.org/filename.html#ex5) are worth looking over to help understand it.
Title: Re: How to copy images to specific (absolute path) folder?
Post by: chuck lee on April 11, 2022, 11:41:55 AM
Thanks for StarGeek's answer.  I looked through the manual again and tried error for a while.  Finally, I found out the  miss  dot(.) is necessary.

exiftool -P -o . '-directory<createdate' -d /home/chuck/lee/%Y/%m/%d  8.jpg

The above command works well.  I learned more from both of you.  Thanks.
Title: Re: How to copy images to specific (absolute path) folder?
Post by: Moonbase59 on April 11, 2022, 12:03:23 PM
Thanks for the info @StarGeek, very helpful!

I succeeded using this:

exiftool -P -o . -d "$HOME/Bilder/%Y/%Y-%m/%Y-%m-%d/%Y%m%d-%H%M%S" '-FileName<${MWG:CreateDate}-${Model}%-c.%le' 20080206-035955-EX-Z80.jpg


Note 1: Linux users might expect a folder path of ~/Bilder/... to work. It does not but instead creates a folder ~ within the current folder.

Note 2: Double apostrophes " for the date string MUST be used for Linux to expand the $HOME environment variable in this case; otherwise, you'll end up with a folder named $HOME inside the current folder.

Note 3: Leaving out the "-o ." part will result in moving the file, instead of copying it.

Note 4: If, for some reason, you'd wish to use above in a crontab, $HOME won't be defined and you'd have to change that against /home/$USER. ($USER is defined in most Linux' crontab environments.)