0

I would like to remove the exif/metadata from all .JPG files in a directory. Here's what I have so far, but part of me doesn't think this will work, so...help?

import os
from gi.repository import GExiv2

rootdir = "c:\directory\subdirectory\subdirectory2"

def noMeta(file):
    exif = GExiv2.Metadata(file + ".jpg")
    exif.clear_exif()
    exif.clear_xmp()
    exif.save_file()

for root, dir, files in os.walk(rootdir):
    for file in files:
        if file.lower().endswith(".jpg"):
            noMeta(file)
Roguey
  • 13
  • 2
  • Have you ran the code against real files? What error are you getting? – Spinor8 Jul 07 '18 at 01:21
  • I haven't run the code at all yet, tbh. I'm a little hesitant to run this since I've never written anything that touches the directory like this. – Roguey Jul 07 '18 at 01:36
  • 1
    Create a test directory and run it on the test directory. If we don't see the outputs how would we know whether there are issues. It's your code on your system. – Spinor8 Jul 07 '18 at 01:52
  • Of the top of my head, I would say that you would need to feed your "root" variable into your function. – Spinor8 Jul 07 '18 at 01:53

1 Answers1

0

Do you really want ...Metadata(file + ".jpg") because file already has .jpg on it.

I don't know anything about GExiv2. FWIW, the piexif library seems to be maintained:

import os
import piexif

rootdir = "c:\directory\subdirectory\subdirectory2"

def noMeta(file):
  print("gutting exif data from {}".format(file))
  piexif.remove(file)

for root, dir, files in os.walk(rootdir):
  for file in files:
    if file.lower().endswith(".jpg"):
      noMeta(os.path.join(root, file))
keithpjolley
  • 2,089
  • 1
  • 17
  • 20
  • And definitely create a test directory and copy some files in there to see if it does what you want. You'll want to recopy the files after each test because you'll be changing the files as you test. – keithpjolley Jul 07 '18 at 02:46