ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: amuelder on February 08, 2016, 04:25:56 PM

Title: Moving and renaming in Windows
Post by: amuelder on February 08, 2016, 04:25:56 PM
Hello,

I shoot JPG and RAW on my Fuji. I'm on Windows 7. My goal is to use ExifTool to copy all images into this structure:

c:\users\andy\pics\YYYY\mm-dd\yymmdd_image_###_FilmMode.ext
In other words: ..\pics\2016\01-29\160129_image_001_Astia.jpg
### being a consecutive number

Preferrably even with sub folder after the date for JPG and for RAF files.

1.) Create subfolder bases on Date
I got this one to work:
exiftool "-Directory<DateTimeOriginal" -d %%Y/%%m-%%d/ .


But not this one
exiftool "-Directory<DateTimeOriginal" -d %%Y/%%m-%%d/%%e .
or exiftool "-Directory<DateTimeOriginal" -d %%Y/%%m-%%d/%%e/ .

Why not?

2.) I tried to rename the files, completely without success.
Can someone please point me in the right direction or even post a solution to this?
For example:
exiftool -r -d %%Y%%m_image_%%1.3C.%%%e "-filename<CreateDate" .
Renames my file to literaly %Y%m_image_001.JPG.
No matter how many %-signs I add infront of the Year and the Month, it just won't show the Year or the Month.

On top of this: I got the FilmMode Tag from another post here. Thanks again! But unfortunately I don't manage to include this in the code above.
exiftool -r -d %%Y%%m_image_%%1.3C_${FilmMode;}.%%%e "-filename<CreateDate" .
Please help.

Sorry if I missed something.

Thanks and regards
Andy
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 08, 2016, 07:34:27 PM
Is this in a batch file or on the command line?

If on the command line, then you should only be using single percent signs in date formatting codes except in the case of %c, %d, %f and %e.  When used in a date formatting code, as with the -d option as you are doing, the percent sign in %c, %d, %f and %e needs to be doubled.

If used in a batch file, then all percent signs need to be doubled (https://support.microsoft.com/en-us/kb/75634).

For example, your second to last command would be
exiftool -r -d %Y%m_image_%%1.3C.%%e "-filename<CreateDate" .
on the command line or
exiftool -r -d %%Y%%m_image_%%%%1.3C.%%%%e "-filename<CreateDate" .
in a batch file.

Take a look at renaming examples (http://www.exiftool.org/exiftool_pod.html#renaming_examples) and FileName and Directory tags (http://www.exiftool.org/filename.html) for some more details.

Your last command, I don't think you can add a tag to a -d date format string.  You have to format that part in the tag assignment part
exiftool -r -d "%Y%m_image_%%1.3C" "-filename<${CreateDate}_${FilmMode;}.%e" .

Notice that in this example, there is only one percent sign in front of the e.  That's because it is not in the date formatting string.  And of course, double all percent signs if using a batch file.

Title: Re: Moving and renaming in Windows
Post by: amuelder on February 09, 2016, 12:20:34 AM
Hello Stargeek,

Thank you, again. I'm running this in a batch file.
I read the examples but I didn't understand why some need only a single % and other need double %. I do now.
I do a second pass for the renaming with the FilmMode after the first pass.

exiftool -r -d C:\Users\Andy\pics\private/%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C.%%%%e "-filename<CreateDate" .
exiftool -r "-filename<%%f_${FilmMode;}.%%e" C:\Users\Andy\pics\private/


This works fine now. Thank you.
Andy
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 10, 2016, 01:55:18 PM
Glad to hear it!
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 10, 2016, 05:25:26 PM
May I ask for additional assistance?

Fuji seems to have quite extensive names for some of their film modes, e.g. "F1b/Studio Portrait Smooth Skin Tone (Astia)".
Whereas I would prefer to just rename the file to
160207_image_354_Astia.JPG
instead of
160207_image_354_F1bStudio Portrait Smooth Skin Tone (Astia).JPG

I'm trying to fix this with the If condition. Where is my mistake?
exiftool -k -if "$Filmmode = 'F1b/Studio Portrait Smooth Skin Tone (Astia)'" "-filename<%%f_Astia.%%e" -ext JPG .
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 10, 2016, 06:55:57 PM
Since ExifTool was created using perl, various bits of how it works are basically perl code.  In this case, the equal sign is the assignment operator and won't work with your if condition.

What you want to use is the string equals operator, eq.  So try this command:
exiftool -k -if "$Filmmode eq 'F1b/Studio Portrait Smooth Skin Tone (Astia)'" "-filename<%%f_Astia.%%e" -ext JPG .
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 02:39:22 AM
Sorry, that doesn't seem to work either.
I'm running this in a batch file and get the following response:

Warning: Invalid tag name '%f_astia.%e' - ./test.JPG

What I don't understand, because in another thread I learned that this command successfully renames the files:

exiftool "-filename<%%f_${FilmMode;}.%%e" a.jpg

There's only a slight deviation ${FilmMode;} against Astia
Title: Re: Moving and renaming in Windows
Post by: Phil Harvey on February 11, 2016, 07:23:43 AM
StarGeek was very close, but made an easy mistake (using "<" instead of "=" when simply assigning a value).  Try this:

exiftool -k -if "$Filmmode eq 'F1b/Studio Portrait Smooth Skin Tone (Astia)'" "-filename=%%f_Astia.%%e" -ext JPG .

The problem is that "<" expects either a tag name, or an expression containing tag names preceded by "$" characters.  Since there are no "$" characters, it interprets %f_Astia.%e as a tag name.

- Phil
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 08:30:10 AM
Perfect. Thank you.
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 09:19:54 AM
Another problem. More a logical one than a programming issue.

My intention is to use ExifTool to
1. Copy all files from the SD card onto the local harddrive
2. Rename the files and place them in a certrain folder structure.
3. Amend the FilmMode to Filename

In a batch file I use one ExifTool command to accomplish step 1 and 2. Then I use a second command to accomplish step 3. Once those files are renamed, if I use this batch file again, the second command will rename all existing files double, triple, ..

Command 1:
exiftool -k -r -d "c:\Users\andym\Pictures\temp_raw\%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C.%%%%e" "-filename<CreateDate" H:\DCIM

Command 2:
exiftool -if "$Filmmode eq 'F0/Standard (Provia)'" "-filename=%%f_Provia.%%e" -ext JPG DIR

What is the best logic to avoid this?
Option A) Insert a third command line to move all files from temporary folder to final folder.
The downside is double file movement.

Option B) Somehow get ExifTool to work only on unprocesed files.
But how?

What is your opinion?
Title: Re: Moving and renaming in Windows
Post by: Phil Harvey on February 11, 2016, 09:38:06 AM
You could do this in a single command:

exiftool -k -r -d "c:/Users/andym/Pictures/temp_raw/%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C" "-filename<${CreateDate}.%%e" "-filename<${CreateDate}${filmmode;$_ = /Provia/ ? '_Provia' : ''}.%%e" H:\DCIM

The first filename argument is necessary for the case where FilmMode doesn't exist.

Note that this command should move the images from the SD card, not just copy them.  You should add -o dummy/ to copy the files instead.  It is best not to write to the SD card in case it has some problems.  After the images are copied and you have suitable backups, then format the SD card to remove the images.  Just deleting images from an SD card is dangerous.

Also note that this command won't copy files that aren't writable by ExifTool (ie. AVI files).  So you may want to add explicit -ext options for all of the files you want to copy.  Also, this won't copy files that don't have a CreateDate tag.

- Phil
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 10:19:40 AM
Phil,

thanks for your explanation. I will add the -o dummy/ argument to copy the file. I don't do movies. "Stills-only" kinda guy. Formatting is also my preferred choice.

However, regarding the one-command solution, I'm not sure this will work.

Fuji offeres several FilmModes. I use around 7-8 of them. Because some of them have rather long descriptions in the tag, I use IF-command to amend the filename by a shorter version.

exiftool -if "$Filmmode eq 'F0/Standard (Provia)'" "-filename=%%f_Provia.%%e" -ext JPG .
exiftool -if "$Filmmode eq 'F2/Fujichrome (Velvia)'" "-filename=%%f_Velvia.%%e" -ext JPG .
exiftool -if "$Filmmode eq 'F1b/Studio Portrait Smooth Skin Tone (Astia)'" "-filename=%%f_Astia.%%e" -ext JPG .
exiftool -if "$Filmmode eq 'Classic Chrome'" "-filename=%%f_ClassicChrome.%%e" -ext JPG .
exiftool -if "$Filmmode eq 'Pro Neg. Hi'" "-filename=%%f_ProNegHi.%%e" -ext JPG .
exiftool -if "$Filmmode eq 'Pro Neg. Std'" "-filename=%%f_ProNegStd.%%e" -ext JPG .
exiftool -if "$Saturation eq 'None (B&W)'" "-filename=%%f_BW.%%e" -ext JPG .
exiftool -if "$Saturation eq 'B&W Yellow Filter'" "-filename=%%f_BW-Yellow.%%e" -ext JPG .
exiftool -if "$Saturation eq 'B&W Red Filter'" "-filename=%%f_BW-Red.%%e" -ext JPG .
exiftool -if "$Saturation eq 'B&W Green Filter'" "-filename=%%f_BW-Green.%%e" -ext JPG .



Would you put all this in one single command?
Title: Re: Moving and renaming in Windows
Post by: Phil Harvey on February 11, 2016, 11:21:44 AM
This type of complex logic is better suited to a user-defined tag.  This may be done with the attached config file and the following command:

exiftool -config MyName.config -k -r -d "c:/Users/andym/Pictures/temp_raw/%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C" "-filename<${MyName}.%%e" -ext jpg H:\DCIM

This will copy and rename the JPG files.  It seems you may want to copy the others too (but not rename them in the same way?):

exiftool -k -r -d "c:\Users\andym\Pictures\temp_raw\%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C.%%%%e" "-filename<CreateDate" --ext jpg H:\DCIM

- Phil
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 11:58:19 AM
Thank you. I will give this a try later on.

The Fuji FilmMode is an in-camera preset regarding color and contrast rendition.

The Raw files are equally imported, but I won't add the FilmMode suffix to the filenames since it's raw. Finally I place each type in a different sub-folder: /%%Y/%%m-%%d/%%%%e/ But only JPGs should show the FilmMode.

After years of working on only CR2 files, I just started with Fuji this year. I like their JPG rendering. By having the FilmMode mentioned in the name I want to learn which type works in which way.
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 11, 2016, 12:46:57 PM
Quote from: Phil Harvey on February 11, 2016, 07:23:43 AM
StarGeek was very close, but made an easy mistake (using "<" instead of "=" when simply assigning a value).

And it's a mistake I will probably keep making unless I actually double check commands to make sure they work.  I KNOW the difference between the two, but still mess them up when I'm not paying full attention.
Title: Re: Moving and renaming in Windows
Post by: Phil Harvey on February 11, 2016, 12:54:36 PM
That's a mistake I've made too.

- Phil
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 04:00:59 PM
Phil, thank you so much. I'm not a programmer. So this is highly appreciated.

I'm assuming I could integrate this to also to add this Filmmode to keywords. Am I right?

exiftool -config Andy.config -k -r -o dummy/ -d "c:/Users/andym/Pictures/temp_raw/%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C" "-filename<${Andy}.%%e" "-Keywords-=${Andy}" "-Keywords+=${Andy}" -ext jpg H:\DCIM

But the keyword written is ${Andy} and not Astia for example.
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 11, 2016, 04:34:25 PM
Try using ${MyName} instead of ${Andy}.

The config file creates a new tag with the name MyName
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 04:44:13 PM
I had MyName exchanged by Andy in the config file.
After returning to MyName, now the Keyword shows ${MyName}

The file amendment works perfectly: 160211_image_001_ProNegHi.JPG
It's the keyword that doesn't go with the tag.
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 11, 2016, 04:55:21 PM
Ah, gotcha.  I jumped to conclusions and didn't fully read the command.

If you revert to Andy, try this instead:
"-Keywords-<Andy" "-Keywords+<Andy"

or if you keep MyName:
"-Keywords-<MyName" "-Keywords+<MyName"

In this case you are copying a tag, so you need the < option.  You can also use ${Andy}/${MyName} format as well.  If you are modifying the tag you are adding, then you must use the DollarsignBraceTagBrace format.

Title: Re: Moving and renaming in Windows
Post by: amuelder on February 11, 2016, 05:03:35 PM
Sorry, but that way the keyword is now
IPTC    Keywords        c:/Users/andym/Pictures/temp_raw/2016/02-11/%e/160211_image_%1.3

I thought I could just use the user-defined tag Andy not only in the filename but also for the keywords.

exiftool -config Andy.config -k -r -o dummy/ -d "c:/Users/andym/Pictures/temp_raw/%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C" "-filename<${Andy}.%%le" "-Keywords-<${Andy}" "-Keywords+<${Andy}" -ext jpg H:\DCIM

I tried "=" as well as "<" signs.


I just realized that won't work either. Because the underscore _ is part of the return from the config-file. Which will lead to e.g. Keyword = _Astia once I got it figured out how to fix the above issue. Sorry to keep bugging you guys.
Title: Re: Moving and renaming in Windows
Post by: StarGeek on February 11, 2016, 05:29:03 PM
Sorry for making so many mistakes in reading this thread.

Do you want just the FilmMode part of "Andy" or "FilmMode_Saturation" part?

I think a change to the config file would be in order to allow more flexibility. 

Title: Re: Moving and renaming in Windows
Post by: amuelder on February 12, 2016, 01:11:18 AM
Good morning Stargeek,

no problem. I'm grateful that you guys are so helping.

Unfortunately the "Filmmode" as it is called in the camera is stored in the tag "FilmMode" for the colored profiles. For B&W profiles this is stored in the tag "Saturation".

I would like to the rename JPG (not RAF) files according to this: yymmdd_image_###_Filmmode.jpg
The Filmmode being either the shortened version for the colored profiles or the description of the saturation for B&W pictures respectively.

And for future references, because the pictures will be renamed after final touch-up in Lightroom, I would like to add these Filmmode tags also as Keyword. So I can filter for them in Lightroom later on. That's why I was hoping to be able to use the custom-tag "Andy" in the filename as well as for the Keywords.

Thanks again!
Andy
Title: Re: Moving and renaming in Windows
Post by: Phil Harvey on February 12, 2016, 07:19:36 AM
You should edit the config file to remove the CreateDate stuff if you want to just use the FilmMode and Saturation in the Keywords.

- Phil
Title: Re: Moving and renaming in Windows
Post by: amuelder on February 20, 2016, 12:01:54 PM
Hello Phil, hello Stargeek,

sorry that I need to come back, but I have 2 last items that I don't get to work:

Firstly I would like to use the config file to not only rename the files but also add the same "item" to keyword.

e.g. 160212_image_112_ProNegHi.jpg and add the keyword ProNegHi to it.

Attached the config file you gave me. Here's the code I use it with:
exiftool -config Andy.config -r -o dummy/ -d "c:/Users/andym/Pictures/temp_raw/%%Y/%%m-%%d/%%%%e/%%y%%m%%d_image_%%%%1.3C" "-filename<${MyMode}.%%le" -ext jpg H:\DCIM

Attached the config file you gave me. Can you please help me with this? Thank you!

Andy
Title: Re: Moving and renaming in Windows
Post by: Phil Harvey on February 21, 2016, 02:45:34 PM
I think you want to add something like this to the command: "-keywords+<mytag"

You'll have to define what MyTag is.  Also, you may want to write XMP Subject instead of IPTC Keywords.

- Phil