Reputation: 45
I have the following script that works just fine except that it can't handle duplicate file names. How can I simply amend it so that if a picture with the same name is found it simply adds an increment at the end of the file name e.g. if file IMG_20170404_170509.JPG is found twice the second instance will be rename IMG_20170404_170509_1.JPG and if another is found then it will be IMG_20170404_170509_2.JPG, etc.
Here is my current script:
exiftool -o . '-Directory<$createdate/${model;}' -d /volume1/Synology/Pictures/Pictures/post_2016/%Y/%m/ -r /volume1/photo/"input"/
Thanks
P.S. I know there is a < between -Directory and $Createdate in the above script but if I include it my message on this board is truncated (yes I know I'm a real novice at all this. Apologies).
Upvotes: 2
Views: 2083
Reputation: 5781
Because you want to change the filename as well as the directory, you'll have to use the Filename
pseudo tag instead of the Directory
pseudo tag.
Try this command:
exiftool -o . '-Filename<$createdate/${model;}/%f%+c%E' -d /volume1/Synology/Pictures/Pictures/post_2016/%Y/%m
-r /volume1/photo/"$input"/
You can include directory paths when you are renaming a file (see 3rd paragraph of FileName and Directory tags). The %f
holds the name of the file. The %c
variable is a counter to be added in the case of a filename collision. Adding a plus sign to it will place an underscore in front of the counter number (see the docs on the -w option). The %E
adds the extension, including the leading dot (a lowercase e would not include the leading dot).
Upvotes: 2