Move/Copy Files into new directory structure on another drive

Started by 23Kev, September 02, 2020, 06:34:58 PM

Previous topic - Next topic

23Kev

Hi,
I'm using exiftool to move a few TB of disorganised images from a Windows machine to a date hierarchy structure on a Synology NAS. I've been successful in getting this command to work.
exiftool -r -o . -d %Y/%m "-directory<filemodifydate" "-directory<createdate" "-directory<datetimeoriginal" . which creates the folder structure correctly and (while testing) copies the images to the new structure.
I have a couple of additional things I'd like to do.

  • Create the structure and copy/move the files into a completely different drive, its a mapped network drive to the synology (Z:\Drive\migratedphotos)
  • Output the errors and logs to a file so I can review what has happened
For the issue of the drive I've tried searching and can only find examples where people want to put it on to the same drive in a different structure, I'm definitely not a computer noob, I feel like I should be able to get this but its just not working for me. I've tried heaps of combinations but can't get it to work.

Thanks a lot for your help and a huge thank you to Phil for the tool, amazing!

StarGeek

Quote from: 23Kev on September 02, 2020, 06:34:58 PM
Create the structure and copy/move the files into a completely different drive, its a mapped network drive to the synology (Z:\Drive\migratedphotos)

You can add the directory path to either the tag copy section or the -d (dateFormat) option format string.
"-directory<Z:\Drive\migratedphotos\$filemodifydate"
or
-d "Z:\Drive\migratedphotos\%Y/%m"

The second version has the benefit of affect all time tags but there are occasions when it might be a hindrance.  For example, if you wanted the camera Model as part of the file path in between two date sections.

QuoteOutput the errors and logs to a file so I can review what has happened

See the -efile option.  It's pretty new so I don't know much about it.

There's also the -v (verbose) option which gives a lot of the internal processing data.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

23Kev

Fantastic, thanks so much.
I'm using the 2nd option with success. -efile is good at outputting file details with errors, but it doesn't show what the error actually is. Also tried using > copylog.txt at the end of the command but that just outputs the final details of whats happened, not the individual error lines.

Maybe there is another option?

StarGeek

You can redirect the STDERR to a file by adding
2>error.txt
or combine error and regular log
1>copylog.txt 2>&1

These are not exiftool options, but rather a function of the CMD/Shell/etc.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

23Kev

Thanks again for your help, I've been able to move to majority of my files, so am going well.
My next issue is a bit of a strange one. Both my wife and I have always used Canon cameras and there have been various times where the naming of the files matches between 2 or 3 cameras in the same months. To clarify, in 05/2005, we have two files named IMG_0123.JPG, one from a 300D and the other from an S70. I'd like to append a short version of the camera model to the end of the file name, so the files copy correctly. There is a few months where there were three cameras with similar names in the same period.

I worked out the below would show the ModelID if CanonModelID contains 300D.
exiftool -CanonModelID -if "$CanonModelID =~m/300D/" img_0465.jpg

I then tried using the below to append a static string to the end of the name.
exiftool -r -d "-filename<%f_'300D'.%e" -if "$CanonModelID =~m/300D/" .
But this doesn't work, all it does is show the exif data for all files, I assume it has something to do with the 300D string I've included. I don't want to have the full model name as its too long.

What I then need to do is have multiple -if statements, something like the below
if ModelID =~ 300D then append _300D
if ModelID =~ S70 then append _S70
if ModelID =~ 350D then append _350D
if ModelID =~ 40D then append _40D
else, ignore

My other issue is in some of the folders I'm copying I've had an "Exports" (or similar crap name) folder for the edits and exports I've made to photos, generally including resizing them. When they are exported the name of the file is the same. I don't want to keep them, but when I've ran exiftool on the folder, it copies the small file first and doesn't copy the original due to a file with the same name already existing. Am I able to do a check if a file does exist, compare file sizes and overwrite the existing file if the one being copied is larger.

StarGeek

Quote from: 23Kev on September 04, 2020, 07:29:55 AM
I then tried using the below to append a static string to the end of the name.
exiftool -r -d "-filename<%f_'300D'.%e" -if "$CanonModelID =~m/300D/" .
But this doesn't work, all it does is show the exif data for all files, I assume it has something to do with the 300D string I've included.

This is Common Mistake #5c.  When assigning values to a tag you use the greater/less than symbols to copy one tag to another and an equal sign when assigning a static value.  Since there isn't an actual tag name in the above command (the %f doesn't count as a tag), you would use an equal sign instead of less than sign.

QuoteI don't want to have the full model name as its too long.

Hmm...  that would be so much easier.

QuoteWhat I then need to do is have multiple -if statements, something like the below
if ModelID =~ 300D then append _300D
if ModelID =~ S70 then append _S70
if ModelID =~ 350D then append _350D
if ModelID =~ 40D then append _40D
else, ignore

Multiple separate commands, one for each if, would be the simplest way.  I can think of a way to cover each of the Model names, but the ignore part messes that up.  I'll have to do some testing to find an all in one command.

QuoteAm I able to do a check if a file does exist, compare file sizes and overwrite the existing file if the one being copied is larger.

No, exiftool can only work on one file at a time.  It can't read data from two separate files and compare them.  I'd suggest looking into the edited file to see if there's a tag that would allow you to exclude it with an -if option.  Usually something like Software or CreatorTool would contain the name of the program that did the editing.  Or if the edited are always below a certain size while the originals are above that size, something like
-if "$ImageHeight<640 and $ImageWidth<640"
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Try
exiftool -r -d "-Testname<%f${Model;$_=m/(300D|s70|350D|40D)/i ? '_'.$1 : ''}.%e"  /path/to/files/

This uses the less than symbol because an actual tag (Model) is used.

If this works, replace Testname with Filename to actually rename the files.

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

olball

Quote from: StarGeek on September 04, 2020, 11:45:30 AM
Try
exiftool -r -d "-Testname<%f${Model;$_=m/(300D|s70|350D|40D)/i ? '_'.$1 : ''}.%e"  /path/to/files/


I think there is still a small glitch (as in the original command). The -d switch expects an argument. So it eats the filename assignment.
Because you are not using any dates in the assignment, remove the -d switch. So the command should be:

exiftool -r "-Testname<%f${Model;$_=m/(300D|s70|350D|40D)/i ? '_'.$1 : ''}.%e"  /path/to/files/

StarGeek

Good catch, olball.  I was just copy/pasting and didn't notice that.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

23Kev

Thanks so much for the advice both of you, really, really appreciate it. I can see where I went wrong previously.
I'll work on using one of the Tags you mention to work out if the file is the original or not, good idea.