ExifTool Forum

ExifTool => Archives => Topic started by: Archive on May 12, 2010, 08:54:13 AM

Title: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by bv on 2007-12-17 18:54:14-08]

How to rename a file and move it to a different drive and directory based on the -DateTimeOriginal tag when both operations uses a different -D format.

I have created the following @ ArgFile example. it contains the details of what I am trying to do and why it does not work.

If anyone knows how I can do this successfully (does not have to be the same approach), I am all ears.

Code:
# EXIFTool ArgFile (windows standalone version 7.06
# Uasge:
#    F:\Photos\1980_01_01>exiftool -@ bv_FIXALL.arg -common_args img_0008.jpg
#
# Trying to perform the following tasks:
# 1 Set the IPTC DateCreated: 2007:09:05
#   Makes backup of original file
# 2 Sets the following
#   IPTC          CopyrightNotice: (c) 2007 by Brooks Vaughn. All rights reserved.
#   XMP-xmpRights Owner: Brooks Vaughn
#   IFD0          Artist: Brooks Vaughn
#   File          Comment: email BrooksVaughn@xxx.xxx for information, usage, and licensing. All
# 3 Rename File in the following format:
#   2007-0905-163014_100-0008.txt, 2007-0905-163014_100-0008-01.txt,
#   2007-0905-163014_100-0008-02.txt
# 4 Moving the newly renamed file
#     - Create a directory (Q:\Photos\2007_09_05)
#     - Move the newly renamed file (2007-0905-163014_100-0008.txt) to Q:\Photos\2007_09_05
#       where folder "2007_09_05" is created from the DateTimeOriginal TAG
#
# ISSUES
#
# 1 I had to break up into different -EXECUTE sections because each uses a
#   different -D (date format) in it's processing.
# 2 I had to envolk using -common_arg otion as each section could not see the
#   filename passed to it after the first section executed.
# 3 Unable to get section #4 working within the executation of this file
#   because after the filename is changed in Section #3, it is still looking
#   for the original filename.
#
# NOTES
#
# 1 There is a case change with the original filename "IMG_0008.JPG"
#   was backed up and renamed to "img_0008.jpg_original"
#
# BEGIN Processing
#
# 1 Set the IPTC DateCreated: 2007:09:05
#   Makes Backup of Original file
# WORKING
-P
-d
   "%Y:%m:%d""
   -DateTimeOriginal>DateCreated
-execute
#
# 2 Sets More Data
# WORKING
-P
-d
   %Y
-CopyrightNotice<(c) ${DateTimeOriginal} by Brooks Vaughn. All rights reserved.
-Owner=Brooks Vaughn
-Artist=Brooks Vaughn
-Comment=email BrooksVaughn@hotmail.com for information, usage, and licensing. All unauthorized usage is strictly forbidden.
-execute
#
# 3 Rename File
# WORKING
-P
-d
   %Y-%m%d-%H%M%S
   -FileName<${DateTimeOriginal}_${filenumber}%.8f%-2c.%ue
-execute
#
# 4 Move the renamed file to New Direct, create if not exists
#
# Works if standalone and envolked using the new file name
# UNABLE to get working. I suspect that it does not know what the
#   new filename is so it fails to find a file to move
-d
   %Y_%m_%d
   -Directory<Q:\Photos\${DateTimeOriginal}
#
# Then End
#
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by exiftool on 2007-12-17 19:44:49-08]

You can solve your problems with 3 and 4 by setting the directory and
filename together:

Code:
-d
Q:/Photos/%Y_%m_%d/%Y-%m%d-%H%M%S
-filename<${DateTimeOriginal}_${filenumber}%.8f%-2c.%ue

(note, I haven't tested this so there may be typos)

The alternative is to create a couple of
user-defined
tags
to help you out:  One (DateTime2) to give an unformatted date for
copying to IPTC:DateCreated, and the other (Year) to extract the year
from DateTimeOriginal for the Copyright tag.  With these, you could
get away with a single -d format, and everything could be
accomplished in a single step.

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        DateTime2 => {
            Require => 'DateTimeOriginal',
            ValueConv => '$val',
        },
        Year => {
            Require => 'DateTimeOriginal',
            ValueConv => '$val=~s/:.*//; $val',
        },
    },
);

- Phil
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by exiftool on 2007-12-17 19:47:57-08]

Sorry.  I said "The alternative" above, but this was an editing artifact.
In fact, the user-defined tags must be used in combination with
setting the directory/filename together to accomplish this in a
single step.

- Phil
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by bv on 2007-12-17 20:40:04-08]

Philip,

It works great. You are pure Genius. I would have never thought of specifiying the -d Q:/Photos/%Y_%m_%d/%Y-%m%d-%H%M%S in format in this way. I only downladed Exiftools yesterday and have only spent 16+ hours trying to figure out the syntax and make it accomplish my reorganization of 63,000+ files.

Is the user-defined tags example you provided worth trying?

My next step is to try testing using the -r and to also process not only the JPG file but also the CR2 files.

Did you have a way to combine steps 1 and 2?

Thanks again,

- Brooks
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by exiftool on 2007-12-17 23:42:48-08]

You ask if the user-defined tags are worth trying.  If you can
reduce your processing from 3 to 1 steps, then it will go
three times faster.  And with 63k files to process, this could
make it worth while.

With the user-defined tags in place, all steps are combined
together with the following argfile:

Code:
# EXIFTool ArgFile (windows standalone version 7.06
# Uasge:
#    F:\Photos\1980_01_01>exiftool -@ bv_FIXALL.arg -common_args img_0008.jpg
#
-P
-DateTime2>IPTC:DateCreated
-CopyrightNotice<(c) ${Year} by Brooks Vaughn. All rights reserved.
-Owner=Brooks Vaughn
-Artist=Brooks Vaughn
-Comment=email BrooksVaughn@hotmail.com for information, usage, and licensing. All unauthorized usage is strictly forbidden.
-d
Q:/Photos/%Y_%m_%d/%Y-%m%d-%H%M%S
-filename<${DateTimeOriginal}_${filenumber}%.8f%-2c.%ue

- Phil
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by exiftool on 2007-12-18 00:01:55-08]

I wasn't paying attention when I cut 'n pasted your command line
comment, but of course you no longer need to use the
-common_args argument.

- Phil
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by bv on 2007-12-18 00:26:43-08]

Hi Phil,

Do I put user-defined tags (as you wrote in the previos messages) at the bottom of the .exiftool_config file or put just the definations "DateTime2" and "Year" into the existing section?

Brooks
Title: Re: How to rename a file and move it to a different drive and directory
Post by: Archive on May 12, 2010, 08:54:13 AM
[Originally posted by exiftool on 2007-12-18 01:12:47-08]

That was a complete config file I posted.  The rest of the sample
ExifTool_config defines a bunch of other tags as examples,
and you don't need these.

- Phil