| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 | "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>Common ExifTool Mistakes</title> |
| 6 | <link rel=stylesheet type='text/css' href='style.css' title='Style'> |
| 7 | <style type="text/css"> |
| 8 | <!-- |
| 9 | pre { color: #800; margin-left: 2em } |
| 10 | ol.index { margin: 0; padding: 0 0 0 2em } |
| 11 | --> |
| 12 | </style> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div class='index'> |
| 16 | <ol class='index'> |
| 17 | <li><a href="#M1">Missing Duplicate Tags</a></li> |
| 18 | <li><a href="#M2">Over-use of *.*</a></li> |
| 19 | <li><a href="#M3">Over-scripting</a></li> |
| 20 | <li><a href="#M4">Writing Multiple Tags</a></li> |
| 21 | <li><a href="#M5">Redirecting Tags</a></li> |
| 22 | </ol> |
| 23 | </div> |
| 24 | <h1 class='up'>Common Mistakes when using ExifTool</h1> |
| 25 | |
| 26 | <a name="M1"></a> |
| 27 | <h3>1. Missing Duplicate Tags</h3> |
| 28 | <blockquote>By default, ExifTool will suppress duplicate tags in the output. |
| 29 | Often this is desirable but sometimes one can be fooled into thinking |
| 30 | that information doesn't exist when it is just hidden by another tag |
| 31 | with the same name. For instance, the following command won't necessarily |
| 32 | return all of the EXIF tags: |
| 33 | <pre>exiftool -exif:all image.jpg |
| 34 | </pre> |
| 35 | To avoid this problem, use the <code>-a</code> option. |
| 36 | </blockquote> |
| 37 | |
| 38 | <a name="M2"></a> |
| 39 | <h3>2. Over-use of Wildcards in File Names (eg. "<code>*.*</code>")</h3> |
| 40 | <blockquote>It is often preferable to specify a directory name (eg. "<code>.</code>") instead |
| 41 | of using wildcards (eg. "<code>*.*</code>") for a number of reasons: |
| 42 | <ol type='a'> |
| 43 | <li>"<code>*.*</code>" will process any file with a "." in the name. This includes files |
| 44 | that ExifTool should not normally process (like the "_original" backup files for |
| 45 | example). By specifying a directory name instead, ExifTool will process only |
| 46 | supported file types. Or the <code>-ext</code> option may be used to process |
| 47 | specific file types.</li> |
| 48 | <li>"<code>*.*</code>" will process any <b>sub-directories</b> which contain "." |
| 49 | in the name. This may be unexpected.</li> |
| 50 | <li>The <code>-r</code> option (to recursively process sub-directories) is only |
| 51 | effective when a directory name is specified, so it doesn't work when |
| 52 | "<code>*.*</code>" is specified (unless the first-level directories have a "." |
| 53 | in the name, as mentioned in point b above).</li> |
| 54 | <li>Arguments like "<code>*.jpg</code>" are a problem on systems with |
| 55 | case-sensitive file names (like OS X and Linux) because JPG images with |
| 56 | uppercase extensions will be missed. It is better to avoid this problem and use |
| 57 | "<code>-ext jpg .</code>" to process all JPG images in the current directory |
| 58 | because this technique is case-insensitive.</li> |
| 59 | <li>This can be a security problem on systems where the shell automatically |
| 60 | expands wildcards (eg. Mac and Linux) because a malicious arrangement of file |
| 61 | names could potentially have unwanted effects since they may be interpreted as |
| 62 | ExifTool options (see <a href="index.html#security">Security Issues</a>).</li> |
| 63 | <li>There are problems using wildcards to match files with Unicode characters in |
| 64 | their names on Windows systems.</li> |
| 65 | </ol> |
| 66 | </blockquote> |
| 67 | |
| 68 | <a name="M3"></a> |
| 69 | <h3>3. Over-scripting</h3> |
| 70 | |
| 71 | <blockquote>Often users write shell scripts to do some specific batch processing |
| 72 | when the exiftool application already has the ability to do this either without |
| 73 | scripting or with a greatly simplified script. This includes the ability to |
| 74 | recursively scan sub-directories for a specific file extension (case insensitive), |
| 75 | rename files from metadata values, and move files to different directories. |
| 76 | </blockquote> |
| 77 | |
| 78 | <blockquote>For example, this Unix script (from |
| 79 | <a href="https://web.archive.org/web/20171223023104/http://www.tuxradar.com/answers/433">here</a>): |
| 80 | |
| 81 | <pre>find -name '*.jpg' | while read PIC; do |
| 82 | DATE=$(exiftool -p '$DateTimeOriginal' $PIC | |
| 83 | sed 's/[: ]//g') |
| 84 | touch -t $(echo $DATE | sed 's/\(..$\)/\.\1/') $PIC |
| 85 | mv -i $PIC $(dirname $PIC)/$DATE.jpg |
| 86 | done |
| 87 | </pre> |
| 88 | |
| 89 | may be replaced with this single command: |
| 90 | <pre>exiftool -d %Y%m%d "-filename<datetimeoriginal" "-filemodifydate<datetimeoriginal#" -ext jpg -r .</pre> |
| 91 | |
| 92 | Running as a single command is much faster because the startup time of loading |
| 93 | ExifTool is significant.</blockquote> |
| 94 | |
| 95 | <a name="M4"></a> |
| 96 | <h3>4. Writing/Copying Multiple Tags</h3> |
| 97 | <blockquote>Any number of tags may be specified on a single command line, but |
| 98 | often people execute a separate command to write or copy each tag, which is very |
| 99 | inefficient. Combining all of the tag assignments into a single command avoids |
| 100 | the significant overhead of launching exiftool for the subsequent commands. For |
| 101 | example: |
| 102 | <pre>exiftool -artist=phil -modifydate=now -tagsfromfile %d%f.xmp -xmp:title -xmp:description -ext jpg c:\images |
| 103 | </pre> |
| 104 | The <code>-@</code> option may be used to read command-line arguments from a |
| 105 | file, and may be useful in situations where there are a large number of |
| 106 | arguments.</blockquote> |
| 107 | |
| 108 | <a name="M5"></a> |
| 109 | <h3>5. Errors and Inefficiencies when Redirecting Tags</h3> |
| 110 | |
| 111 | <blockquote>The syntax to redirect tags when copying is <code>"-DSTTAG<SRCTAG"</code>, |
| 112 | but the syntax also allows a string containing tag names (prefixed by <code>$</code>) |
| 113 | to be used in place of <code>SRCTAG</code>. Three <b>common mistakes</b> when using this |
| 114 | syntax are: |
| 115 | <ol type='a'> |
| 116 | <li>Adding a leading "<code>-</code>" before the <code>SRCTAG</code>. (eg. |
| 117 | <code>"-EXIF:Artist<-XMP:Creator"</code>) This is <b>wrong</b>, and the tag will |
| 118 | not be copied. (It should be <code>"-EXIF:Artist<XMP:Creator"</code>.)</li> |
| 119 | <li>Adding a leading "<code>$</code>" when copying a simple tag. (eg. |
| 120 | <code>"-comment<$filename"</code>). This is usually not necessary <i>(see |
| 121 | exception below)</i> and it is less efficient for ExifTool to process the source |
| 122 | string than it is to copy the tag directly. Also, values of list-type and |
| 123 | shortcut tags are concatenated in the string rather than being copied |
| 124 | individually, and wildcards are not allowed. Another difference is that a minor |
| 125 | warning is generated if a tag doesn't exist when interpolating its value in a |
| 126 | string (with "<code>$</code>"), but isn't when copying the tag directly.</li> |
| 127 | <li>Using "<code>=</code>" instead of "<code><</code>" to copy a tag, or |
| 128 | using "<code><</code>" instead of "<code>=</code>" to assign a value. |
| 129 | <table class=box><tr><td>"<code><</code>" is used for copying, in which case the |
| 130 | source (right-hand-side) operand is interpreted as either |
| 131 | <ol type='i'> |
| 132 | <li>a tag name (if the operand does not contain a "<code>$</code>" symbol), or</li> |
| 133 | <li>a string containing tag names prefixed by "<code>$</code>" symbols (if the operand contains a "<code>$</code>" symbol).</li> |
| 134 | </ol> |
| 135 | "<code>=</code>" is used to assign a simple tag value, and the source operand is |
| 136 | a string that is written directly to the destination tag.<br> |
| 137 | (And the combination "<code><=</code>" is used to assign a tag value from the contents of a file.)<br> |
| 138 | </td></tr></table></li> |
| 139 | </ol> |
| 140 | An exception to rule "b" above occurs when trying to copy the value of one tag |
| 141 | to a group of different tags, for example: |
| 142 | <pre>exiftool "-time:all<datetimeoriginal" FILE <span class=blk>(WRONG!)</span></pre> |
| 143 | The above command doesn't work because the destination tag name of "All" writes |
| 144 | to the tag with the same name as the source (ie. only "DateTimeOriginal"). However, |
| 145 | when interpolated in a string the identity of the source tag is lost, so the |
| 146 | following command will write to all tags in the Time group: |
| 147 | <pre>exiftool "-time:all<$datetimeoriginal" FILE</pre> |
| 148 | (Note that single quotes would be necessary in the above command under Mac/Linux.) |
| 149 | </blockquote> |
| 150 | |
| 151 | <hr> |
| 152 | <i>Last revised Mar 11, 2021</i> |
| 153 | <p class='lf'><a href="index.html"><-- Back to ExifTool home page</a></p> |
| 154 | </body> |
| 155 | </html> |