简体   繁体   English

Exiftool-如何基于pdf所在的文件夹名称添加作者标签

[英]Exiftool - how to add author tag based on the folder name the pdf is residing in

Trying to write a script that would make exiftool write the result of 尝试编写一个脚本,使exiftool写入以下内容:

echo "${PWD##*/}"

to the author metadata tag. 到作者元数据标签。

Let's say the pdf is located in /ResearchJournal/Research1/manual1.pdf 假设pdf位于/ResearchJournal/Research1/manual1.pdf

I want to use exiftool to append Research1 as the author of manual1.pdf. 我想使用exiftool附加Research1作为manual1.pdf的作者。

When I'm in the /ResearchJournal/Research1 folder, I type echo "${PWD##*/}" in the terminal and I get the result Research1 . 当我在/ ResearchJournal / Research1文件夹中时,我在终端中键入echo "${PWD##*/}"并得到结果Research1

However I don't know how to write the exiftool command correctly. 但是我不知道如何正确编写exiftool命令。

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. 我知道您可以使用exiftool -author=Research1 ,但是我想编写命令,这样我就可以在多个不同的文件夹上使用它,而不必每次都对实际的文件夹名称进行硬编码。

Here's an example from the Exiftool forum. 这是 Exiftool论坛中的示例。 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. 这将遍历子目录( -r ),获取目录路径,根据斜杠字符将其拆分为一个数组,获取数组的最后一项,即pdf所在的目录,并将其复制到Author标签。 I would also suggest adding -ext pdf to the command, so it would only process PDFs. 我还建议将-ext pdf添加到命令中,以便仅处理PDF。

This command doesn't require you to CD into the directory. 此命令不需要您将CD插入目录。 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. 在sh / bash shell中测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM