简体   繁体   中英

Exiftool export JSON with Python

I´m trying to extract some metadata and store them in a JSON file using Exiftool via Python.

If I run the following command (according to the documentation) in the CMD it works fine, generating a temp.json file:

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.

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 . See this StackOverflow question .

For a exiftool solution, you would use the -W ( -tagOut ) option , specifically -W+: C./Users/XXX/Desktop/test_folder/temp.json . See Note #3 under that link.

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.

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