ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Gary on November 23, 2015, 10:39:15 PM

Title: Avoiding needless rewriting during recursive commands
Post by: Gary on November 23, 2015, 10:39:15 PM
I am working on a script to recurse through a very large directory. I need to modify some files to remove segments and individual tags.

If I give a typical generic recursive command to remove the items without knowing they actually exist, ExifTool will rewrite the file even if the file actually requires no modification. Found this by turning verbose on at level "-v1".

I'd prefer not to touch files that don't need to be changed and would like to be able to log what files are changed so that I can spot check to make sure everything went as planned.

Am I on the right track trying something like the following?
My tests seem to indicate that this actually does work and seems to be quicker.
Is there a better or more elegant way?

exiftool -v1 -ext JPG -ext CR2 -ext NEF -IFD0:artist= -if "$IFD0:artist" -r "C:\Users\Gary Gauthier\Desktop\Strip" > "C:\Users\Gary Gauthier\Desktop\Strip\log.txt

It results in the following logfile.

Deleting IFD0:Artist
======== C:/Users/Gary Gauthier/Desktop/Strip/IMG_0036_Annotated.jpg
Rewriting C:/Users/Gary Gauthier/Desktop/Strip/IMG_0036_Annotated.jpg...
  Editing tags in: APP0 APP1 IFD0 JFIF
  Creating tags in:
JPEG APP1 (13518 bytes):
  Rewriting IFD0
  ExifByteOrder = II
    - IFD0:Artist = 'Gary D. Gauthier'
  Rewriting ExifIFD
  Rewriting MakerNoteCanon
  Rewriting CanonCameraSettings
  Rewriting CanonFocalLength
  Rewriting CanonShotInfo
  Rewriting CanonCameraInfoUnknown
  Rewriting CustomFunctions30D
  Rewriting CanonFileInfo
  Rewriting ProcessingInfo
  Rewriting MeasuredColor
  Rewriting ColorData3
  Rewriting InteropIFD
  Rewriting GPS
  Rewriting IFD1
JPEG APP13 (562 bytes):
JPEG APP1 (7925 bytes):
JPEG DHT (416 bytes):
JPEG DQT (130 bytes):
JPEG SOF0:
JPEG SOS
-------- C:/Users/Gary Gauthier/Desktop/Strip/IMG_0036_Master.JPG (failed condition)
-------- C:/Users/Gary Gauthier/Desktop/Strip/IMG_6000_Annotated.CR2 (failed condition)
-------- C:/Users/Gary Gauthier/Desktop/Strip/IMG_6000_Master.CR2 (failed condition)
    2 directories scanned
    3 files failed condition
    1 image files updated
Title: Re: Avoiding needless rewriting during recursive commands
Post by: Phil Harvey on November 24, 2015, 07:13:06 AM
Hi Gary,

> exiftool a.jpg a.tif -artist=me
    2 image files updated
> exiftool a.jpg a.tif -artist=
    2 image files updated
> exiftool a.jpg a.tif -artist=
    0 image files updated
    2 image files unchanged


The files are not modified in the last command.  It does write a temporary file, but then deletes it again after determining that nothing was changed.

Adding the -if statement will add an extra processing pass to first read the metadata, so it will be slower if a significant fraction of the files satisfy the -if condition.

- Phil
Title: Re: Avoiding needless rewriting during recursive commands
Post by: Gary on November 24, 2015, 09:10:54 AM
Thanks, Phil. I had tried what you suggest and was misled, by the log file contents, that it was doing a "real" change.

If it's not actually resulting in a permanent changed "original", can I do something to log the names of the files actually changed? I'd like to be able to go back and spot check the changed files. I could write to a separate directory, but this would seem to involve a lot of work in merging the two sets of files after verification.
Title: Re: Avoiding needless rewriting during recursive commands
Post by: Phil Harvey on November 24, 2015, 09:18:01 AM
You can add -v0 or -progress to see the files that weren't changed.

- Phil
Title: Re: Avoiding needless rewriting during recursive commands
Post by: Gary on November 24, 2015, 09:33:12 AM
Thanks, Phil. The suggestion works fine with -v0 instead of -v1. Will try the -progress switch and see which I like best.