Hi everyone,
first of all thank you for this wonderful program and all the hints in the forum!
I am working on a program to sort my photos and film files (~200k unsorted files but who is counting...?)
My target structure is
(1) Getting the files from the SourceDirectory
(2) Rename it as follows: Year-Month-Day_HourMinuteSecond
(3) Create Data Structure as follows: Year \ Year-Month \ Year-Month-Day
(4) Storing the files in E:\TargetDirectory
I have devised the following Commandline:
C:\ExifTool\_Programs\exiftool -config C:\ExifTool\_Programs\OldestDateConfig "-XMP:DateCreated<OldestDateTime" -overwrite_Original "-filename<${OldestDateTime;}%%-c.%%e" -d "%%Y-%%m-%%d_%%H%%M%%S" E:\SourceDirectory -v "-Directory<OldestDateTime" -d "%%Y\%%Y-%%m\%%Y-%%m-%%d" E:\SourceDirectory -ext JPG -ext MOV -ext MP4 -ext PNG .
The Config file was derived from this thread (which is great!) https://exiftool.org/forum/index.php?topic=7986.0
I now have the following problems:
a) The part with the -d ... for the -filename command (2) conflicts with the -d... for the directory command (3). Is there a way to separate the two parts? I found "-execute" but cannot seem to get it to work properly.
b) At the moment, the TargetDirectory is the folder where the .bat file is located. I would like to be flexible to save the files somewhere else. I found "-o E:\Targetdir/" but cannot place it properly so that the command works.
c) I assume that the use of two instances of E:\SourceDirectory is necessary - or can it be avoided?
I greatly appreciate your help with this
If I missed this in a search, my apologies.
Thanks
Jannes
Not reading everything at the moment but what I think you should do is remove the Directory part and include the directory as part of the Filename. The file path can be included as part of the -d (-dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) or as part of the tag copy. See Example #13 (https://exiftool.org/filename.html#ex13), which creates a directory structure out of the Date and Model. It also uses the DateFmt helper function which would be required for have two different date format strings.
Thank you - I tried to implement this over the course of the day but did not find the proper way to do it.
I have now the following:
C:\ExifTool\_Programs\exiftool -config C:\ExifTool\_Programs\OldestDateConfig "-XMP:DateCreated<OldestDateTime" -v -r -overwrite_Original "-filename<%%Y\%%Y-%%m\%%Y-%%m-%%d\${OldestDateTime#;DateFmt(("%%Y")}%%-c.%%e" -ext JPG E:\01_Unsorted
but it fails to rename the files and does not move them properly. Also it does not capture the data for the path anympre (the directories re called %Y and %Y-%m now instead of dates)
I use Windows 10 with Exiftool 12.2.9.0
See FAQ #27 (https://exiftool.org/faq.html#Q27). You are formatting for use in a BAT file, but it appears you are using the command line due to the % characters in the resulting path.
The %c/%e need to be doubled because they are file name variables used in a date format string. If you use this command in a BAT file, then those will have to be doubled again to %%%%-c.%%%%e.
Finally, I should have mentioned that the linked example was for Mac/Linux/Powershell. You have to reverse the single/double quotes for CMD.
I haven't tested it, but this looks correct for CMD. Double all % signs for a bat file.
exiftool -config C:\ExifTool\_Programs\OldestDateConfig "-XMP:DateCreated<OldestDateTime" -v -r -overwrite_Original "-filename<%Y\%Y-%m\%Y-%m-%d\${OldestDateTime#;DateFmt(('%%Y')}%%-c.%%e" -ext JPG E:\01_Unsorted
Thank you StarGeek - I just realizes (thanks for the hint) that the syntax for commandline and batchfile are different - I hadn't known and will investigate further.
I found the following solution for a cmd line in the .bat
C:\ExifTool\_Programs\exiftool -config C:\ExifTool\_Programs\OldestDateConfig -execute "-XMP:DateCreated<OldestDateTime" -execute "-filename<${OldestDateTime;}%%-c.%%e" -d "%%Y-%%m-%%d_%%H%%M%%S" -execute "-Directory<OldestDateTime" -d "%%Y\%%Y-%%m\%%Y-%%m-%%d" -common_args -Overwrite_Original -r -ext AVI -ext GIF -ext GP -ext HEIC -ext JPEG -ext JPG -ext MOV -ext MP4 -ext MTS -ext PNG -ext TIF
%%-c and %%e are working properly (unsure why I do not have to translate to %%%%)
I could not get this code
exiftool "-filename<${CreateDate#;DateFmt('%%Y')}"
to run properly, therefore I substituted with -execute
Sole problem remaining is that a file (1984 without extension) is created in the folder where the .bat file is located, but that is minor.
Thank you for the help!
One question for learning purposes - please excuse the simplistic view, I don't have much background in this area.
As I understand now there are (probably amongst more sophisticated means like programming languages) the following ways to write this code for newbies
Command Line in Unix using single ', single %
Command line in a DOS Window using double ", doubling the %
Command Line in Windows Batch file using double ", doubling (or quadrupling?) the %
C:\ExifTool\_Programs\exiftool -config C:\ExifTool\_Programs\OldestDateConfig -execute "-XMP:DateCreated<OldestDateTime" -execute "-filename<${OldestDateTime;}%%-c.%%e" -d "%%Y-%%m-%%d_%%H%%M%%S" -execute "-Directory<OldestDateTime" -d "%%Y\%%Y-%%m\%%Y-%%m-%%d" -common_args -Overwrite_Original -r -ext AVI -ext GIF -ext GP -ext HEIC -ext JPEG -ext JPG -ext MOV -ext MP4 -ext MTS -ext PNG -ext TIF .
Proper Windows Batch file - how does this look like?
Quote from: Jannes on November 03, 2022, 06:59:55 AM%%-c and %%e are working properly (unsure why I do not have to translate to %%%%)
The filename type variables,
%c/
%d/
%e/
%f, only have to be doubled like that when they are in a
-d (
-dateFormat) (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) format string (and doubled again in a bat file). Since they've been moved out of the format string and into the main tag copy part, they do not need to be expanded to four
% signs.
QuoteSole problem remaining is that a file (1984 without extension) is created in the folder where the .bat file is located, but that is minor.
Not sure why that would happen without actually checking the file.
Also, that first
-execute after the
-config option should be removed.
Quote from: Jannes on November 03, 2022, 07:48:17 AMCommand Line in Unix using single ', single %
Yes
QuoteCommand line in a DOS Window using double ", doubling the %
Double quotes yes, and single quotes when needed inside the double quoted option, such as when using a helper function (https://exiftool.org//exiftool_pod.html#Helper-functions). But percent signs
% are single. Only when you use the filename
% variables (see
-w (
-TextOut) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut)) inside a
-d (
-dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat), you have to double them. This is because several of the Common Date Format Codes (https://exiftool.org/filename.html#codes) are the same as the filename
% variables.
QuoteCommand Line in Windows Batch file using double ", doubling (or quadrupling?) the %
Quoting is the same as above. The
% signs are doubled (FAQ #27 (https://exiftool.org/faq.html#Q27)) because
% signs are used to indicate variables in a bat file (see How-to: Double %% symbols, why are they needed in a batch file? (https://ss64.com/nt/syntax-percent.html)). And because the filename
% variables in a Date Format string already have to be doubled, in a bat file they have to be doubled again, to four
%%%% signs.
QuoteC:\ExifTool\_Programs\exiftool -config C:\ExifTool\_Programs\OldestDateConfig -execute "-XMP:DateCreated<OldestDateTime" -execute "-filename<${OldestDateTime;}%%-c.%%e" -d "%%Y-%%m-%%d_%%H%%M%%S" -execute "-Directory<OldestDateTime" -d "%%Y\%%Y-%%m\%%Y-%%m-%%d" -common_args -Overwrite_Original -r -ext AVI -ext GIF -ext GP -ext HEIC -ext JPEG -ext JPG -ext MOV -ext MP4 -ext MTS -ext PNG -ext TIF .
Proper Windows Batch file - how does this look like?
Looks good except for that first
-execute, which is unneeded and probably lists all the metadata for all the files before actually doing anything. And you probably don't need the full path to the config file since it's in the same directory as exiftool, though there's no harm as is. But it should be possible to combine a lot of that
I would think that this would work.
XMP:DateCreated is written as part of the command. The directory has been added to the Date Format string. The
-overwrite_original option (https://exiftool.org/exiftool_pod.html#overwrite_original) should make sure that the file is written with the new data and moved to the new directory/filename without leaving a copy behind (see Writing "FileName" and "Directory" tags -> Notes (https://exiftool.org/filename.html#Notes))
C:\ExifTool\_Programs\exiftool -config OldestDateConfig "-XMP:DateCreated<OldestDateTime#" "-filename<${OldestDateTime}%%-c.%%e" -d "%%Y\%%Y-%%m\%%Y-%%m-%%d\%%Y-%%m-%%d_%%H%%M%%S" -Overwrite_Original -r -ext AVI -ext GIF -ext GP -ext HEIC -ext JPEG -ext JPG -ext MOV -ext MP4 -ext MTS -ext PNG -ext TIF .
StarGeek,
... and again thank you very much for this follow-up!
Cheers Jannes