Hi team,
I saw the post where Phil showed the way to using a stack of -if conditions to define 10-year brackets of date (taken or created...) and then set the directories according to 1960s, 1970s, 1980s etc.
I find organizing files by decades is very useful.
Is it possible to directly format the output directories by using a string handling command/regular expression, which would generate output like "YYY\YYYY\YY-MM\", i.e. "cutting the first three digits from the 4-digit year, thus indicating the decade? It might yield a much shorter command to solve this task.
Thanks,
Uwe
You could use something like this
exiftool -d "%Y/%y-%m/%%F" "-testname<${DateTimeOriginal#;DateFmt('%Y');s/\d$//}/$DateTimeOriginal" /path/to/files/
Which has these results
C:\>exiftool -g1 -a -s -DateTimeOriginal y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
---- ExifIFD ----
DateTimeOriginal : 1975:09:22 11:53:22
======== y:/!temp/Test4.jpg
---- ExifIFD ----
DateTimeOriginal : 2020:04:28 23:49:51
2 image files read
C:\>exiftool -d "%Y/%y-%m/%%F" "-testname<${DateTimeOriginal#;DateFmt('%Y');s/\d$//}/$DateTimeOriginal" y:\!temp\Test3.jpg y:\!temp\Test4.jpg
'y:/!temp/Test3.jpg' --> '197/1975/75-09/Test3.jpg'
'y:/!temp/Test4.jpg' --> '202/2020/20-04/Test4.jpg'
0 image files updated
2 image files unchanged
But it can be set to do the full decade with a zero in the right spot
C:\>exiftool -d "%Y/%y-%m/%%F" "-testname<${DateTimeOriginal#;DateFmt('%Y');s/\d$//}0/$DateTimeOriginal" y:\!temp\Test3.jpg y:\!temp\Test4.jpg
'y:/!temp/Test3.jpg' --> '1970/1975/75-09/Test3.jpg'
'y:/!temp/Test4.jpg' --> '2020/2020/20-04/Test4.jpg'
0 image files updated
Fantastic. This does the trick - many thanks!
Uwe
@StarGeek: Interesting that you did this
${DateTimeOriginal#;DateFmt('%Y');s/\d$//}0
instead of this
${DateTimeOriginal#;DateFmt('%Y');s/\d$/0/}
... thinking outside of the box I guess. ;)
- Phil
Well, yeah, there is that :D
Actually, it was a last second thought just before I posted. Popped it in, posted, and went to bed.
Help!
/mnt/user/Downloads/Image-ExifTool-12.25# ./exiftool -g1 -a -s -DateTimeOriginal /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
---- ExifIFD ----
DateTimeOriginal : 2010:03:01 17:42:49
but...
/mnt/user/Downloads/Image-ExifTool-12.25# ./exiftool -d "%Y/%y-%m/%%F" "-testname<${DateTimeOriginal#;DateFmt('%Y');s/\d$//}0/$DateTimeOriginal" /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
Warning: No writable tags set from /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
Warning: Invalid tag name '0/' - /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
0 image files updated
1 image files unchanged
or...
/mnt/user/Downloads/Image-ExifTool-12.25# ./exiftool -d "%Y/%y-%m/%%F" "-testname<${DateTimeOriginal#;DateFmt('%Y');s/\d$/0/}/$DateTimeOriginal" /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
Warning: No writable tags set from /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
Warning: Invalid tag name '/' - /mnt/user/Photos/_Archive/2010/2010-03/2010-03-01-174249.jpg
0 image files updated
1 image files unchanged
Greetings RadOD. Both of your commands conducted properly inside the Windows cmd.exe, so Im thinking maybe to just change the quotes????
Im no ideas how they should change, but if still having troubles, this can be another way with less quoting...
exiftool -d '%Y%m/%%F' -TestName'<${DateTimeOriginal;s|(..)(.)(.)(..)|$1${2}0/$1$2$3/$2$3-$4|}' file.jpg
Im just guessing with using the single-quotes, but maybe you can experiment until it starts conducting properly.
Ahh, the quotes! Thanks - I'm in Linux not Windows. I was looking for "\" vs "/" problems because of the invalid tag name '/' error!
Yes, on Linux/Mac, you need to use single quotes to enclose a parameter that has a $ to avoid the shell from interpreting it as a variable name. Double quotes would be used internally to the single quotes, so the DateFmt part would be DateFmt("%Y")