1

I'm looking to use Python to iterate through all the files in a folder and run the exiftool command on each file, so in the end I should have x amount of files each with their own exiftool output to run grep commands on.

Currently I have this code (I made it from pseudocode I took down whilst at a lecture, so it's probably not that accurate)

#!/usr/bin/python  
import os
import subprocess
import sys
for root,dirs,files in os.walk(".", topdown=False):
    for name in files:
        print("echo", os.path.join(root, name))
        subprocess.call(["exiftool", os.path.join(root, name)])
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • I fixed up your psuedocode to at least be runnable. – Martijn Pieters Jan 13 '15 at 14:25
  • 1
    And with that edit, I probably solved your question already. Try running it now.. – Martijn Pieters Jan 13 '15 at 14:27
  • Thanks a ton, letting it run now (will take a bit of time but it's running so hopefully all goes well :D). – user4294282 Jan 13 '15 at 14:29
  • Any ideas on how I would change this to execute exiftool so it gives me a seperate txt file output for each file it goes through? – user4294282 Jan 13 '15 at 16:24
  • Have you checked the `exiftool` documentation to see how it could do that? Or does it produce the information on stdout and you need to redirect it? – Martijn Pieters Jan 13 '15 at 16:25
  • Normally with exiftool you specify the filetype and if you want to store the result then put it into a textfile like so: exiftool * .jpg > exifjpgoutput.txt. I want to do an output for each file in a txt - so it would go exiftool "x file" > "xfile.txt" – user4294282 Jan 13 '15 at 17:14
  • [Python: How to Redirect Output with Subprocess?](http://stackoverflow.com/q/4965159) you mean? – Martijn Pieters Jan 13 '15 at 17:22

1 Answers1

0

If you're already using python, you could simply use an existing Python library that allows you to read Exif tags, and avoid all error-prone parsing.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94