Pulling filename and directory name into metadata

Started by Beholder3, November 09, 2022, 01:45:18 PM

Previous topic - Next topic

Beholder3

Hi,
I have some old photos without proper metadata and filenaming. As a preparation before doing some automated renaming I first want to save the existing filenames and foldernames in their metadata, so I can later reuse them if I want. With foldername I mean the name of the folder directly above the file (not a full path).

So far I have experimented with
-IPTC:Caption-Abstract<filename -IPTC:ObjectName<directory -EXIF:ImageDescription<filename
But there I run into two issues:
1. The filename copies the full filename including extension. I do want to get rid of the file extension.
2. The directory only fills the field with an "."

I have no idea how to fix this. My practical issue is that searching or google searching anything on the web about "filename" or "directory" really is not leading anywhere.

If anyone has a tip on how to do it correctly that would be nice.

fxstein

#1
You can apply the following logic to your filename to strip the extension: (I am using XMP:PreservedFileName in my case)

-XMP:PreservedFileName<${FileName;s/\.[^.]*$//}

For context you can see more examples here: https://github.com/fxstein/GoProX/blob/a1ff12131392e540ce2d06790fb65ac64f5a2965/goprox#L510
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

StarGeek

If you are using version 12.22+, you can use the Basename tag for the filename without the extension.

To get parent directory name by itself, you can use (swap quotes on Mac/Linux)
"-IPTC:ObjectName<${Filepath;$_=(split '\/',$_)[-2]}"

I used Filepath here instead of Directory in case you are CDing into the directory and using a dot for the directory.  Changing the -2 to -1 will give the filename.  Changing it to -3 or more(less?) will move up the directory path.

See this post for more details.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype