mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 23:43:12 +00:00
251 lines
13 KiB
HTML
251 lines
13 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>FileName and Directory tags</title>
|
|
<link rel=stylesheet type='text/css' href='style.css' title='Style'>
|
|
</head>
|
|
<body>
|
|
<h2 class='up'>Writing "FileName" and "Directory" tags</h2>
|
|
|
|
<p>By writing the <b>FileName</b> and/or <b>Directory</b> tags, ExifTool can be
|
|
used to rename and/or move images into directories according to any information
|
|
contained in the image. The most useful application of this feature is to
|
|
organize images by date/time, but any other tag value may also be used.</p>
|
|
|
|
<p>Writing the <b>Directory</b> tag moves a file to a specified directory. The
|
|
directory is created if it didn't already exist.</p>
|
|
|
|
<p>Writing the <b>FileName</b> tag renames a file. If the new <b>FileName</b>
|
|
has a directory specification (ie. contains a '<code>/</code>' character), then
|
|
the file is also moved to the specified directory (see example 6 below).
|
|
Existing files will not be overwritten.</p>
|
|
|
|
<p>The <code>%d</code>, <code>%f</code>, <code>%e</code> file name format codes
|
|
may be used to represent the directory, name and extension of the original file
|
|
when specifying <b>FileName</b> and <b>Directory</b> tags via the command-line
|
|
interface. (In a similar way to the <code>-o</code>, <code>-w</code> and
|
|
<code>-tagsFromFile</code> options.) Also, <code>%c</code> may be used to add a
|
|
copy number to the output file name to avoid collisions with existing file
|
|
names. Note that these codes must be escaped with an extra <code>%</code> if
|
|
used within a date format string. Modifiers may also be used to change the
|
|
default behaviour of these format codes. See the <code>-w</code> option in the
|
|
<a href="exiftool_pod.html">application documentation</a> for details.</p>
|
|
|
|
<p>When organizing files by date/time, use of the <code>-d</code> (date format)
|
|
option is essential to specify a format for the filename (and/or directory
|
|
name). The examples below demonstrate the use of this feature. Also, a quick
|
|
reference of <a href="#codes">common date format codes</a> is included.</p>
|
|
|
|
<h3>Notes:</h3>
|
|
|
|
<p>Writing the <b>FileName</b> and/or <b>Directory</b> tags alone causes the
|
|
file to be renamed or moved, not copied. However, if any other tags are written
|
|
at the same time, then the file is rewritten to the new destination and the
|
|
original file is left unchanged. (The only exception to this is
|
|
<b>FileModifyDate</b> tag, which will not cause the file to be rewritten because
|
|
it is the only other writable tag not representing meta information within the
|
|
file.) But if desired, the <code>-overwrite_original</code> option may be used
|
|
in this case to remove the original copy.</p>
|
|
|
|
<p>Conversely, the <code>-o</code> option may be used to force exiftool to
|
|
always create a copy of the file, even if no meta-information tags are written.
|
|
This is true even if the <code>-o</code> option is superseded by writing the
|
|
<b>Directory</b> tag (which may be useful if you want to derive the directory
|
|
name from the values of other tags, see example 5 below).</p>
|
|
|
|
<p>If the <code>-d</code> option is used, the unformatted date/time value must
|
|
be valid (ie. in the form "<code>YYYY:mm:dd HH:MM:SS</code>"), otherwise the
|
|
date formatting will fail and the file will not be renamed or moved.</p>
|
|
|
|
<p>In a Windows batch file, all <code>%</code> characters must be escaped as
|
|
<code>%%</code>. This can result in extreme format codes like
|
|
<code>%%%%f</code> when using the <code>-d</code> option.</p>
|
|
|
|
<h2>Examples</h2>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 1.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -d %Y%m%d_%H%M%%-c.%%e "-filename<CreateDate" DIR
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Rename all images in directory '<code>DIR</code>' to names like
|
|
'<code>20060327_1058-2.jpg</code>', with individual file names derived from the
|
|
value of the CreateDate (plus a copy number with a leading '<code>-</code>' if a
|
|
file with the same name already exists), and with the same extension as the
|
|
original image.
|
|
<p><b>FAQ:</b> <i>"Why doesn't this command rename my files?"</i></p>
|
|
<p>There are 2 common reasons for this:</p>
|
|
<p>a) When a directory name is specified, this command will only rename "writable"
|
|
files in the directory. Use '<code>exiftool -listwf</code>' to list the
|
|
extensions of currently writable file types. The <code>-ext</code> option may
|
|
be used to rename other file types (ie. '<code>-ext avi</code>').</p>
|
|
<p>b) For this command to work, the CreateDate tag must exist in the source
|
|
file. Use '<code>exiftool -createdate FILE</code>' to see if a file contains
|
|
this information. If it doesn't, you may need to use another date/time tag such
|
|
as DateTimeOriginal or FileModifyDate.</p>
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 2.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -d %Y-%m-%d "-directory<datetimeoriginal" image.jpg
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Move '<code>image.jpg</code>' into a directory with a name given by
|
|
DateTimeOriginal, in the form '<code>2006-03-27</code>'.
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 3.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool '-filename<%f_$imagesize.%e' dir
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
This example uses an expression to add the image size to the name of all images
|
|
in directory '<code>dir</code>'. For example, this would remame a 640x480 image
|
|
called '<code>image.jpg</code>' to '<code>image_640x480.jpg</code>'. (Note that
|
|
the single quotes are necessary in Unix shells due to the '<code>$</code>'
|
|
symbol, but double quotes must be used instead when running in a Windows cmd shell.)
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 4.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -r -directory=%e_images/%d pics
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Recursively move all images based in directory '<code>pics</code>' to
|
|
separate directory trees organized by file extension. For instance, in this
|
|
example the file '<code>pics/toys/new_car.jpg</code>' is moved to
|
|
'<code>jpg_images/pics/toys/new_car.jpg</code>'.
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 5.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -r -o %e_images/%d pics<br>
|
|
exiftool -r -o dummy/ -directory=%e_images/%d pics
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Both of these commands have the same effect as example 3 above except that
|
|
images are copied instead of moved since the <code>-o</code> option was used. In
|
|
the second command the trailing '<code>/</code>' on '<code>dummy/</code>' is
|
|
necessary because otherwise '<code>dummy</code>' would be interpreted as a file
|
|
name. This technique of using <code>-o</code> with a dummy directory name is
|
|
necessary when the directory name is derived from the value of other tags (ie.
|
|
'<code>-directory<createDate</code>') and you want the files to be copied
|
|
instead of moved. (Because the values of other tags may not be used with the
|
|
<code>-o</code> option.)
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 6.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -r -d %Y/%m/%d/image_%H%M%S.%%e "-filename<filemodifydate" DIR
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Recusively rename all images in '<code>DIR</code>' and any contained
|
|
subdirectories to the form '<code>image_HHMMSS.EXT</code>' (where
|
|
'<code>ext</code>' is the original file extension), and move them into a new
|
|
directory hierarchy based on date of file modification, with path names like
|
|
'<code>2006/03/27/image_105859.jpg</code>'.
|
|
</blockquote>
|
|
|
|
<p>The following examples demonstrate the interaction of this feature with
|
|
other ExifTool options:</p>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 7.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -filename=new.jpg dir/image.jpg
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Rename '<code>dir/image.jpg</code>' to '<code>dir/new.jpg</code>'.
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 8.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -filename=new.jpg -comment=xxx dir/image.jpg
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Copy '<code>dir/image.jpg</code>', add a new comment, and write output to
|
|
'<code>dir/new.jpg</code>'. The original file '<code>dir/image.jpg</code>' is
|
|
not changed.
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'> 9.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -filename=new.jpg -comment=xxx -overwrite_original dir/image.jpg
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
Rewrite '<code>dir/image.jpg</code>', adding a new comment and writing output to
|
|
'<code>dir/new.jpg</code>'. The original file '<code>dir/image.jpg</code>' is
|
|
removed.
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'>10.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -o tmp/ -filename=new.jpg image.jpg<br>
|
|
exiftool -o tmp/xxx.jpg -filename=new.jpg image.jpg<br>
|
|
exiftool -o tmp/new.jpg image.jpg
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
A file name or directory specified via the <b>FileName</b> or <b>Directory</b>
|
|
tag takes precedence over that specified by the <code>-o</code> option, so these
|
|
three commands all have the same effect: '<code>tmp/new.jpg</code>' is created
|
|
without changing '<code>image.jpg</code>'. Note that in the first command, the
|
|
trailing '<code>/</code>' on '<code>tmp/</code>' is necessary if the
|
|
'<code>tmp</code>' directory doesn't already exist, otherwise '<code>tmp</code>'
|
|
would be taken as a file name and '<code>new.jpg</code>' would be created in the
|
|
current directory. As illustrated in example 4 above, the file is rewritten
|
|
instead of simply being renamed when the '<code>-o</code>' option is used.
|
|
</blockquote>
|
|
|
|
<table cellpadding=6><tr><td valign='top'>11.</td><td bgcolor='#dddddd'><code class='blk'>
|
|
exiftool -directory=dir1 -filename=dir2/out.jpg -o dir3/ dir4/image.jpg<br>
|
|
</code></td></tr></table>
|
|
<blockquote>
|
|
This example demonstrates the priorities of directory names specified using
|
|
different techniques. The output directory is taken from the first directory
|
|
specified from the following list: 1) the <b>Directory</b> tag, 2) the
|
|
<b>FileName</b> tag, 3) the <code>-o</code> option, or 4) the original source
|
|
file, in that order. Note that both the <b>FileName</b> tag and the
|
|
<code>-o</code> option may be used without a directory specification, in which
|
|
case the directory with the next highest priority is used. So in this example,
|
|
the target file is copied (not moved, because the <code>-o</code> option was
|
|
used) to '<code>dir1/image.jpg</code>'. The order of the arguments on the
|
|
command line is not significant.
|
|
</blockquote>
|
|
|
|
<a name="codes"></a><h2>Common Date Format Codes</h2>
|
|
<p>Date format codes are used in the argument to the <code>-d</code> option to
|
|
represent components of the date/time string. The codes listed below are common
|
|
to most systems, but additional codes may be available on your specific system
|
|
-- see your <i>strftime</i> man page for details.</p>
|
|
<blockquote><table>
|
|
<tr><th>%a</th><td>- abbreviated locale weekday name</td></tr>
|
|
<tr><th>%A</th><td>- full locale weekday name</td></tr>
|
|
<tr><th>%b</th><td>- abbreviated locale month name</td></tr>
|
|
<tr><th>%B</th><td>- full locale month name</td></tr>
|
|
<tr><th>%c</th><td>- preferred locale date/time representation</td></tr>
|
|
<tr><th>%d</th><td>- day of month (01-31)</td></tr>
|
|
<tr><th>%H</th><td>- hour on a 24-hour clock (00-23)</td></tr>
|
|
<tr><th>%I</th><td>- hour on a 12-hour clock (01-12)</td></tr>
|
|
<tr><th>%j</th><td>- day of year (001-366)</td></tr>
|
|
<tr><th>%m</th><td>- month number (01-12)</td></tr>
|
|
<tr><th>%M</th><td>- minute (00-59)</td></tr>
|
|
<tr><th>%p</th><td>- 'AM' or 'PM'</td></tr>
|
|
<tr><th>%S</th><td>- seconds (00-59)</td></tr>
|
|
<tr><th>%w</th><td>- weekday number (0-6)</td></tr>
|
|
<tr><th>%W</th><td>- week number of the year (00-53)</td></tr>
|
|
<tr><th>%x</th><td>- preferred locale date representation</td></tr>
|
|
<tr><th>%X</th><td>- preferred locale time representation</td></tr>
|
|
<tr><th>%y</th><td>- 2-digit year (00-99)</td></tr>
|
|
<tr><th>%Y</th><td>- 4-digit year (ie. 2006)</td></tr>
|
|
<tr><th>%Z</th><td>- time zone name</td></tr>
|
|
<tr><th>%%</th><td>- a literal '%' character</td></tr>
|
|
</table></blockquote>
|
|
<p>Note that ExifTool file name format codes may be used inside a date format
|
|
string when a date/time tag is used to set the value of the <b>FileName</b> or
|
|
<b>Directory</b> tags via the command-line interface. In this case, an extra
|
|
'<code>%</code>' must be added to pass the format code through the date/time
|
|
parser:</p>
|
|
<blockquote><table>
|
|
<tr><th>%%d</th><td>- original file directory</td></tr>
|
|
<tr><th>%%f</th><td>- original file name</td></tr>
|
|
<tr><th>%%e</th><td>- original file extension</td></tr>
|
|
<tr><th>%%c</th><td>- copy number (output files only)</td></tr>
|
|
</table></blockquote>
|
|
<p>See the <code>-w</code> option in the <a href="exiftool_pod.html">exiftool
|
|
application documentation</a> for details about special features available
|
|
with these name format codes.</p>
|
|
<hr>
|
|
<p class='lf'><a href="index.html"><-- Back to ExifTool home page</a></p>
|
|
</body>
|
|
</html>
|