[英]Exiftool export JSON with Python
I´m trying to extract some metadata and store them in a JSON file using Exiftool via Python.我正在尝试通过 Python 使用 Exiftool 提取一些元数据并将它们存储在 JSON 文件中。
If I run the following command (according to the documentation) in the CMD it works fine, generating a temp.json file:如果我在 CMD 中运行以下命令(根据文档),它可以正常工作,生成一个 temp.json 文件:
exiftool -filename -createdate -json C:/Users/XXX/Desktop/test_folder > C:/Users/XXX/Desktop/test_folder/temp.json
When managing Exiftool from Python the data is extracted correctly but no JSON file is generated.从 Python 管理 Exiftool 时,数据提取正确,但未生成 JSON 文件。
import os
import subprocess
root_path = 'C:/Users/XXX/Desktop/test_folder'
for path, dirs, files in os.walk(root_path):
for file in files:
file_path = path + os.sep + file
exiftool_exe = 'C/Users/XXX/Desktop/exiftool.exe'
json_path = path + os.sep + 'temp.json'
export = os.path.join(path + ' > ' + json_path)
exiftool_command = [exiftool_exe, '-filename', '-createdate', '-json', export]
process = subprocess.run(exiftool_command)
print(process.stdout)
When I run the code it shows the error:当我运行代码时,它显示错误:
Error: File not found - C:/Users/XXX/Desktop/test_folder > C:/Users/XXX/Desktop/test_folder/temp.json
What am I missing, any ideas on how to get it to work?我错过了什么,关于如何让它工作的任何想法? Thanks!
谢谢!
I believe the problem is that file redirection is a property of the command line and isn't available with subprocess.run
.我认为问题在于文件重定向是命令行的属性,并且不适用于
subprocess.run
。 See this StackOverflow question .请参阅此 StackOverflow 问题。
For a exiftool solution, you would use the -W
( -tagOut
) option , specifically -W+: C./Users/XXX/Desktop/test_folder/temp.json
.对于 exiftool 解决方案,您将使用
-W
( -tagOut
) 选项,特别是-W+: C./Users/XXX/Desktop/test_folder/temp.json
。 See Note #3 under that link.请参阅该链接下的注释 #3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.