Hi,
Is there a way to detect a file name collision and provide a custom resolution?
For example, I want to know if file name would collide and have a chance to resolve it myself by using a tag before exiftool appends its own resolution based on %c. However, I do not want to use this tag if there is no name collision.
Thanks.
You could perhaps do this in 2 passes. The first pass would use %c, then the second pass would use a -if condition to process only files which had the copy numbers in them.
- Phil
How would I detect if there was a name collision?
Like I said, with a -if condition to check for a copy number in the file name. To answer more specifically I need details about the exact format of the file names you would be writing.
- Phil
I am using the following command:
tagName=FileName
target_video_dir=/video
target_photo_dir=/photo
# The following value is obtained by watching directory changes and supplying each new file to the script
source_path=<full path to a source file name>
/opt/bin/exiftool -stay_open 1 -@ - <<-OPTS -common_args \
-"${tagName}"'<${FileModifyDate}%-3c.%e' \
-"${tagName}"'<${MediaCreateDate}%-3c.%e' \
-"${tagName}"'<${CreationDate}%-3c.%e' \
-"${tagName}"'<${DateTimeOriginal}%-3c.%e' \
-"${tagName}"'<${DateTimeOriginal}_${SubSecTimeOriginal;$_.=0 x(3-length)}%-3c.%e' \
-P -q -q "${source_path}"
-if
\$MIMEType =~ /^video\//
-d
${target_video_dir}/%Y/%Y-%m-%d/%Y%m%d_%H%M%S
-execute
-if
\$MIMEType =~ /^image\//
-d
${target_photo_dir}/%Y/%Y-%m-%d/%Y%m%d_%H%M%S
-stay_open
0
OPTS
Note that there are actual tabs in front of the commands within OPTS block. They do get removed by the "-" option of the "here document"
The above command is executed for each new file in a directory. As you can see the directory and file names are based on date and time. The file name suffix would be -nnn if there is a name collision.
The same script can be used to scan all files in the source directory recursively. Example given is for a single file processing.
My biggest problem is knowing where the target file is going to end up.
Interesting use of -stay_open with an input redirect, but why not simple this?:
/opt/bin/exiftool \
-if \$MIMEType =~ /^video\// \
-d ${target_video_dir}/%Y/%Y-%m-%d/%Y%m%d_%H%M%S \
-execute \
-if \$MIMEType =~ /^image\//
-d ${target_photo_dir}/%Y/%Y-%m-%d/%Y%m%d_%H%M%S \
-common_args \
-"${tagName}"'<${FileModifyDate}%-3c.%e' \
-"${tagName}"'<${MediaCreateDate}%-3c.%e' \
-"${tagName}"'<${CreationDate}%-3c.%e' \
-"${tagName}"'<${DateTimeOriginal}%-3c.%e' \
-"${tagName}"'<${DateTimeOriginal}_${SubSecTimeOriginal;$_.=0 x(3-length)}%-3c.%e' \
-P -q -q "${source_path}"
What I would do, although I don't have time right now to provide details, is to add -v to this command, then pipe the output through grep, looking for the expression "--> '(.*-\d{3}\..*)'". This will give you the output file name only if there was a collision. Then do whatever you want to this file.
- Phil
I tried parsing output with -v option but came to a conclusion that it would not help me.
Because the script processes the files as they are copied to a watched directory, the script cannot know about all the collisions for the same file name.
I may just have to implement a periodic scanner or a watch to do another pass on the target directories
Quote from: mif on April 24, 2017, 09:35:45 AM
Because the script processes the files as they are copied to a watched directory, the script cannot know about all the collisions for the same file name.
It will know there is one collision. The problem is if you want %c to count the number of collisions because this won't work if you rename the previous collision files. If this is what you want, then some additional scripting will be required.
- Phil