ExifTool Forum

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

Title: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by mruddick on 2006-02-03 05:10:13-08]

I have two directories on a Win machine, call them C:\pics and D:\pics.

C:\pics has original JPGs with complete camera maker notes.
D:\pics has manipulated JPGs that have lost the camera maker notes.

I found your wonderful tool to replace the camera maker notes.  Works great when I use single filenames as the arguments, i.e. 'exifool -tagsfromfile c:\pics\pic1.jpg d:\pics\pic1.jpg' but I am struggling to get the syntax correct to copy all info from all files in C:\pics to all matching files in D:\pics.

Can you help me out?

Many thanks,
Mike
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by mruddick on 2006-02-03 06:50:55-08]

Well, I found a similar reference on this forum and am using a command line as follows: exiftool -tagsfromfile %d%f.jpg -ext jpg \newdir
      Note that I have moved my directories onto a common drive in case that was causing any problems.   But what I am seeing now is that file1.jpg for example, which has good camera maker notes, when copied with the batch command results in warning message about invalid canonCameraSettings data.  Sure enough, the rewritten file in \newdir does not contain correct data.   What's very odd, however, is if I do the copy as a single command line on a single file, it works fine.   To be clear, 'exiftool -tagsfromfile file1.jpg \newdir\file1.jpg' results in a full copy of exif data (including camera maker info) into the target file, but the batch line command creates the warning and a target file that is missing the camera maker info.    This very well could be expected behavior, I have to admit the command line batch syntax has me a little puzzled...   Thanks,Mike
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by exiftool on 2006-02-03 12:35:16-08]

Hi Mike,

Your command "exiftool -tagsfromfile %d%f.jpg -ext jpg \newdir" will process the files in "newdir" by taking information from the files in the same directory (since you used "%d" in the -tagsfromfile filename).

I think what you wanted to do (using your original file structure), was this:

Code:
   exiftool -tagsfromfile c:\pics\%f.jpg -ext jpg d:\pics

With this command, you copy information from the jpg images in c:\pics to the corresponding images in d:\pics

I hope this clears things up a bit.  I know it can be a bit tricky.
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by mruddick on 2006-02-03 20:19:06-08]

Indeed, that works.  Many thanks.  A bit more playing and I can probably figure out the %d%f substitutions rules better and get really dangerous!

        I did notice that my original files from the camera (c:\pics) had nothing in the 'user comment' field, and after processing with the given command to produce the d:\pics files, now have the string value 'ASCII' in the 'user comment' field.  Not sure what that's about, but thought I'd point it out.  Some more playing and I imagine I'll get the right combo of copying only the fields I need, etc...

        Thanks again for the assistance, I appreciate it.  The work done to create exiftool is impressive.
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by mruddick on 2006-02-03 20:35:03-08]

I should be more explicit when I post. (and I wish I knew why my carriage returns are not being seen in the posts).  Regardless, I do not know that a string value 'ASCII' is being placed in the user comment field.  I am using a different application to display to the EXIF information, inclusive of the makernotes info.  I am not sure yet where the user comment resides that is being displayed differently between a file straight from the camera versus one that has been exiftool'd to match the original data.  All that I know is that when I display the two, which theoretically should have the same info, the original camera file reacts as though there is nothing in the user comment, and the exiftool'd file reacts as though something different is there, and my application responds by displaying 'ASCII'.   I can solve my problem easily enough by not displaying the field (I don't use it currently), but will continue down a path to understand the differences in case it's an odd case that you'd be interested in updating...Mike
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by exiftool on 2006-02-04 16:27:04-08]

Hi Mike,

Sounds good.  My guess is that the original image may contain improperly formatted UserComment data, but that's just a guess.  By the EXIF specification, the first 8 bytes of the UserComment should be either "UNICODE\0" or "ASCII\0\0\0", depending on the character set used.  Some readers don't properly filter this out, so it is possibly that is why you see "ASCII" with your reader after it is rewritten using ExifTool.  If you want to send me a sample image (to philharvey66 at gmail.com), I can tell you for sure what is going on.

About the forum linefeeds...  This forum is odd that way.  You have to explicitly type "
" to insert a linefeed in your text.  (Either that or brace all your text with "
Code:
...
")
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by exiftool on 2006-02-04 21:07:59-08]

No need to send me a sample.  I have found one of my test images (t/images/Olympus.jpg)
which exhibits this behaviour.  This image has a UserComment field which is entirely full
of zeros.

I checked the EXIF specification, and it is legal for the first 8 bytes of UserComment to be all zeros,
and indicates an undefined character set.

The difference you observe is because ExifTool writes UserComments in the ASCII character set,
instead of the "undefined" set used in your image.  But since the comments are likely empty anyway,
these methods are completely equivalent.

The only fault is in the other EXIF reader you are using, which shouldn't be displaying the "ASCII"
since it only specifies the character set, and is not part of the comment itself.
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by mruddick on 2006-02-09 22:25:24-08]

Excellent detective work, that certainly sounds logical based on the behavior I've seen...Mike
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by mruddick on 2006-02-24 06:43:51-08]

Code:
I have a related syntax question now:

What I want to do is copy exif data from pictures that are spread amongst several directories, all branching from a common root.  The target files (to receive the exif data) are named identically to the source files, but all reside in a single directory.

In other words:
C:\dir1\file1.jpg
C:\dir2\file2.jpg

contains EXIF data that I want copied into the files
D:\dirx\file1.jpg
D:\dirx\file2.jpg

I could do

exiftool -tagsfromfile c:\dir1\%f.jpg -ext jpg d:\dirx
exiftool -tagsfromfile c:\dir2\%f.jpg -ext jpg d:\dirx

to accomplish my goal, but since I've got 50+ directories for the source exif data, I'd like to find a way to automate this.  I tried a few variations on the -r option, but had no luck.

Can I get to where I want with a single command line instruction?

Many thanks,
Mike
Title: Re: Copy tagsfromfile between directories?
Post by: Archive on May 12, 2010, 08:53:53 AM
[Originally posted by exiftool on 2006-02-24 14:21:06-08]

Pity you aren't going the other way (copying information from files in a
single directory to files in a hierarchy), because you could do that with:

Code:
   exiftool -r -tagsfromfile d:\dirx\%f.jpg -ext jpg c:\

but that won't work for what you want to do.

In your case you will have to use a script to automate what you want to do.
Using the following command:

Code:
   script_name C:\ D:\dirx

This perl script should do what you want:

Code:
#!/usr/bin/perl -w
use strict;

my $src = shift;
my $dst = shift || die "Must specify source and destination directory\n";
opendir(DIR, $src) or die "Error opening directory $src\n";
my @files = readdir(DIR);
closedir(DIR);
-d $dst or die "$dst is not a directory\n";
my ($file, $jpg);
foreach $file (@files) {
    next if $file =~ /^\./ or not -d "$src/$file";
    print "==== Directory $src/$file:\n";
    opendir(DIR, "$src/$file") or die "Error opening $src/$file\n";
    my @jpgs = readdir(DIR);
    closedir(DIR);
    foreach $jpg (@jpgs) {
        next unless $jpg =~ /\.jpg/i;
        my $srcname = "$src/$file/$jpg";
        my $dstname = "$dst/$jpg";
        print "---- Source file: $srcname\n";
        -e $dstname or warn("Warning: $dstname doesn't exist\n"), next;
        print `exiftool -tagsfromfile "$srcname" "$dstname"`;
    }
}
# end