How to rename file to include current folder name.

Started by publicENEMY, August 13, 2023, 11:40:15 PM

Previous topic - Next topic

publicENEMY

I want to rename my image file from
E:/Temp/exiftool/Processing/Korea/IMG_5008.JPG into
E:/Temp/exiftool/Processing/Korea/Korea_20170223_134335_IMG_5008.jpg
This is the command i use
exiftool -r "-testname<${createdate;}" -d "%%D_%Y%m%d_%H%M%S_%%f%%-c.%%le" "E:\Temp\exiftool\Processing"
The result is
E:/Temp/exiftool/Processing/Korea_20170223_134335_IMG_5008.jpginstead of
E:/Temp/exiftool/Processing/Korea/Korea_20170223_134335_IMG_5008.jpg
How do I fix it?

Phil Harvey

Try this:

exiftool -r "-testname<${createdate;}" -d "%%-1:D_%Y%m%d_%H%M%S_%%f%%-c.%%le" "E:\Temp\exiftool\Processing"

This adds the last directory name at the start of the file name (%-1:D = "Korea"), and doesn't move the file as it would if you use %D (which evaluates to "E:/Temp/exiftool/Processing/Korea").

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

publicENEMY

Hmm. Doesnt work.

Instead of
E:/Temp/exiftool/Processing/Korea/Korea_20170223_134335_IMG_5008.jpgIt looks like this
E:/Temp/exiftool/Processing/Korea/a_20170223_134335_IMG_5008.jpg

StarGeek

Hmmm...  It looks like that %%-1:D in a date format string is being treated as %%-1.D.  If you move it out of the date string, it works properly.

C:\>exiftool -r "-testname<%-1:D_${createdate;}" -d "%Y%m%d_%H%M%S_%%f%%-c.%%le" Y:\!temp\aaaa\Korea\IMG_5008.JPG
'Y:/!temp/aaaa/Korea/IMG_5008.JPG' --> 'Y:/!temp/aaaa/Korea/Korea_20170223_134335_IMG_5008.jpg'
    0 image files updated
    1 image files unchanged
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).