ExifTool Forum

ExifTool => Newbies => Topic started by: paingod on June 29, 2023, 05:54:35 PM

Title: Organize Files Into Folders based on Date by Moving Them
Post by: paingod on June 29, 2023, 05:54:35 PM
I need to move about 50K images from various folders into a fixed target folder by moving them, and if there are duplicates, the duplicate files is labelled with an extra text at the end of the filename e.g. DUP. I did get ChatGPT to whip a code of sorts but it's not working and for the life of me I can't figure what's wrong with it:

exiftool -r -d "C:/path/to/destination/%Y/%m" "-filename<${CreateDate}_${filesequence;$_=sprintf('%02d',$_)}" -o "-$filename" -progress "C:/path/to/source"

Ideally they should be looking at the Exif data, if not if there's a chance - Modified Date
Title: Re: Organize Files Into Folders based on Date by Moving Them
Post by: Phil Harvey on June 30, 2023, 07:29:13 AM
The %c format code allows you to add a number (with an optional leading dash or underline) to the duplicates, but adding other text requires running the command again.  For example:

1. exiftool "-filename<createdate" -r -d "C:/path/to/destination/%Y/%m/%%f.%%e" "C:/path/to/source"

2. exiftool "-filename<createdate" -r -d "C:/path/to/destination/%Y/%m/%%f_DUP.%%e" "C:/path/to/source"

The first command moves all the files, but will give errors for duplicates.  The 2nd command moves the duplicates and adds "_DUP" to the file name.  If there are triplicates you can run another command to move them.

These commands will work if the files are on the same filesystem, but you may have to add "-overwrite_original" to remove the files from the source filesystem if the destination is a different disk.

Also, I recommend having a backup of all your files before doing this because it is hard to recover from a renaming operation if there is a problem with your command.

- Phil
Title: Re: Organize Files Into Folders based on Date by Moving Them
Post by: paingod on June 30, 2023, 11:39:08 AM
Thank you! I think it solved my problem :) moved about half of the library and rest stayed due to invalid EXIF data - loss probably when I was moving them from different libraries/export systems but it worked like a charm. First command worked better as the second command had all my files in the destination folder added with the label DUP. Thank you Phil. You're a lifesaver.
Title: Re: Organize Files Into Folders based on Date by Moving Them
Post by: Phil Harvey on June 30, 2023, 01:28:44 PM
My point was that you needed to run both commands, first 1 then 2.  If the first command copies the files rather than moving them then you need to add -overwrite_original to both commands to remove the files that were copied -- otherwise they'll all get copied again when you run the 2nd command.

Of course, these commands rely on the existence of CreateDate metadata.

- Phil