By writing the FileName and/or Directory tags, ExifTool can be used to rename and/or move images into directories according to any information contained in the image. The most common use of this feature is to organize images by date/time, but any other tag value may also be used.
Writing the Directory tag moves a file to a specified directory. The directory is created if it didn't already exist.
Writing the FileName tag renames a file. If the new FileName
has a directory specification (ie. contains a '
/' character), then
the file is also moved to the specified directory (see
example 6 below). Existing files will not be overwritten.
%e file name format codes
may be used to represent the directory, name and extension of the original file
when specifying FileName and Directory tags via the command-line
interface. (In a similar way to the
-tagsFromFile options.) Also,
%c 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
used within a date format string. Modifiers may also be used to change the
default behaviour of these format codes. See the
-w option in the
application documentation for details.
When organizing files by date/time, use of the
-d (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 list of
of common date format codes is provided for reference.
Writing the FileName and/or Directory tags alone causes the
file to be renamed or moved, not copied. However, if any "real" tags are
written at the same time, then the file is rewritten to the new destination and
the original file is left unchanged. (Only the three writable "pseudo" tags,
FileName, Directory and FileModifyDate, may be set without
causing the file to be rewritten.) If desired, the
option may be used to remove the original copy when the file is rewritten.
-o 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
-o option is superseded by writing the
Directory tag, or through a FileName which includes a directory
specification. (This is useful if you want to derive the directory name from the
values of other tags, see example 5 below. Also see
example 11 for the directory precedence rules.)
-d option is used, the unformatted date/time value must
be valid (ie. in the form "
YYYY:mm:dd HH:MM:SS"), otherwise the
date formatting will fail and the file will not be renamed or moved.
In a Windows batch file, all
% characters must be escaped as
%%. This can result in extreme format codes like
%%%%f when using the
Rename all images in directory '
DIR' to names like '
20060327_1058-2.jpg', with individual file names derived from the value of the CreateDate (plus a copy number with a leading '
-' if a file with the same name already exists), and with the same extension as the original image.
FAQ: "Why doesn't this command rename my files?"
There are 2 common reasons for this:
a) When a directory name is specified, this command will only rename "writable" files in the directory. Use '
exiftool -listwf' to list the extensions of currently writable file types. The
-extoption may be used to rename other file types (ie. '
b) For this command to work, the CreateDate tag must exist in the source file. Use '
exiftool -createdate FILE' 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.
image.jpg' into a directory with a name given by DateTimeOriginal, in the form '
This example uses an expression to add the image size to the name of all images in directory '
dir'. For example, this would remame a 640x480 image called '
image.jpg' to '
image_640x480.jpg'. (Note that the single quotes are necessary in Unix shells due to the '
$' symbol, but double quotes must be used instead when running in a Windows cmd shell.)
Recursively move all images based in directory '
pics' to separate directory trees organized by file extension. For instance, in this example the file '
pics/toys/new_car.jpg' is moved to '
Both of these commands have the same effect as example 3 above except that images are copied instead of moved since the
-ooption was used. In the second command the trailing '
/' on '
dummy/' is necessary because otherwise '
dummy' would be interpreted as a file name. This technique of using
-owith a dummy directory name is necessary when the directory name is derived from the value of other tags (ie. '
-directory<createDate') and you want the files to be copied instead of moved. (Because the values of other tags may not be used with the
Recusively rename all images in '
DIR' and any contained subdirectories to the form '
image_HHMMSS.EXT' (where '
ext' is the original file extension), and move them into a new directory hierarchy based on date of file modification, with path names like '
The following examples demonstrate the interaction of this feature with other ExifTool options:
dir/image.jpg' to '
dir/image.jpg', add a new comment, and write output to '
dir/new.jpg'. The original file '
dir/image.jpg' is not changed.
dir/image.jpg', adding a new comment and writing output to '
dir/new.jpg'. The original file '
dir/image.jpg' is removed.
A file name or directory specified via the FileName or Directory tag takes precedence over that specified by the
-ooption, so these three commands all have the same effect: '
tmp/new.jpg' is created without changing '
image.jpg'. Note that in the first command, the trailing '
/' on '
tmp/' is necessary if the '
tmp' directory doesn't already exist, otherwise '
tmp' would be taken as a file name and '
new.jpg' would be created in the current directory. As illustrated in example 4 above, the file is rewritten instead of simply being renamed when the '
-o' option is used.
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 Directory tag, 2) the FileName tag, 3) the
-ooption, or 4) the source directory, in that order. Note that both the FileName tag and the
-ooption 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
-ooption was used) to '
dir1/image.jpg'. The order of the arguments on the command line is not significant.
Date format codes are used in the argument to the
-d 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 strftime man page for details.
%a - abbreviated locale weekday name %A - full locale weekday name %b - abbreviated locale month name %B - full locale month name %c - preferred locale date/time representation %d - day of month (01-31) %H - hour on a 24-hour clock (00-23) %I - hour on a 12-hour clock (01-12) %j - day of year (001-366) %m - month number (01-12) %M - minute (00-59) %p - 'AM' or 'PM' %S - seconds (00-59) %w - weekday number (0-6) %W - week number of the year (00-53) %x - preferred locale date representation %X - preferred locale time representation %y - 2-digit year (00-99) %Y - 4-digit year (ie. 2006) %Z - time zone name %% - a literal '%' character
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 FileName or
Directory tags via the command-line interface. In this case, an extra
%' must be added to pass the format code through the date/time
%%d - original file directory (including trailing "/" if necessary) %%f - original file name (without the extension) %%e - original file extension (not including the ".") %%c - copy number (output files only)
-w option in the exiftool
application documentation for details about special features available
with these name format codes.
<-- Back to ExifTool home page