Trying to write a script that would make exiftool write the result of
echo "${PWD##*/}"
to the author metadata tag.
Let's say the pdf is located in /ResearchJournal/Research1/manual1.pdf
I want to use exiftool to append Research1 as the author of manual1.pdf.
When I'm in the /ResearchJournal/Research1 folder, I type echo "${PWD##*/}"
in the terminal and I get the result Research1
.
However I don't know how to write the exiftool command correctly.
I know you can use exiftool -author=Research1
, but I want to write the command so that I can just use it on a number of different folders without having to hard code the actual folder name each time.
Here's an example from the Exiftool forum. In your case, your command would be something like:
exiftool '-Author<${directory;my @a=split m(/);$_=$a[-1]}' -r DIR
This would recurse through subdirectories ( -r
), take the directory path, split it into an array based upon the slash character, take the last item of the array, which would be the directory that the pdf was in, and copy that into the Author
tag. I would also suggest adding -ext pdf
to the command, so it would only process PDFs.
This command doesn't require you to CD into the directory. In fact, I think you might have problems if you change directory and use the dot to indicate the current directory and want to process a file in that directory, as it would return .
as the directory to add to the tag. Though if you really need to do that I think I have a note someplace to work around that.
You can make it with following commands:
cd /ResearchJournal/Research1
exiftool -author=${PWD##*/} *.pdf
Tested in the sh/bash shells.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.