I tried to format a file name with a config file, but I got stuck. I managed to print the file name in the desired format:
MacBook-Air-van-Fulco:~ Fulco$ exiftool -p '${FileName;s/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.*)/$1:$2:$3 $4:$5:$6$7/}' /Users/Fulco/Pictures/20130428132110-DSCN5071.JPG
2013:04:28 13:21:10-DSCN5071.JPG
I don't know how to integrate this formatting into a config file. I tried something like this, but it didn't work:
FileName1 => {
Require => {0 => 'FileName'},
ValueConv => '$val;s/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.*)/$1:$2:$3 $4:$5:$6$7/",
},
FileName1 => {
Require => {
0 => 'FileName',
},
PrintConv => 'sprintf($val[0];s/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.*)/$1:$2:$3 $4:$5:$6$7/)',
},
What am I doing wrong? Any suggestions?
- Fulco
Your first version with some mods
FileName1 => {
Require => {0 => 'FileName'},
ValueConv => '$val=~s/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.*)/$1:$2:$3 $4:$5:$6$7/ ? $val : undef',
},
Changed the semicolon to the perl match operator. Added in a conditional operator that returns the value if a substitution is made, undefined if it fails.
Output
C:\>exiftool -filename1 X:\!temp\aa
======== X:/!temp/aa/20130428132110-DSCN5071.JPG
File Name 1 : 2013:04:28 13:21:10-DSCN5071.JPG
======== X:/!temp/aa/2015-03-31_0043.JPG
1 directories scanned
2 image files read
You can also just put the code in your command. Anytime you want, just replace $filename with ${FileName;s/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.*)/$1:$2:$3 $4:$5:$6$7/}
Thanks once again StarGeek. Worked perfectly!
This is exactly what I need to do for a bunch if pictures I got off my dad's old computer. All the filenames follow the format: 20160818_195634. I would like them to match my files which look like: 2016-08-18 19.56.34. None of his pictures have any time information in the metadata.
I've been trying for days to figure out how to use this to create a config file and make it work, but I can't. Any help would be greatly appreciated.
I'm using
Exiftool Version: 10.67
MacOS: 10.13
Sublime Text 2
Try this:
exiftool '-testname<${filename;s/(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})/$1-$2-$3 $4.$5.$6/}' DIR
And if this looks good, then change "testname" to "filename" to actually rename the files.
- Phil
Yup. That worked perfectly. Thank you, so much.
Funnily enough I tried almost exactly this. When I compared them side-by-side I realized that in all my frustration I left out a backslash and completely overlooked it for two days.