Fill FileProperties->Comment with a part of the filename

Started by exwul, November 07, 2014, 04:17:42 AM

Previous topic - Next topic

exwul


Following scenario:
I have filenames that end up with 3 or 4 digits + extension.

Like the below:
SomeFileName-B1-IR027.JPG
SomeFileName-B1-IR028.JPG
SomeFileName-B1-KL003.JPG
SomeFileName-B1-KL004.JPG
SomeFileName-B1-KL057.JPG
SomeFileName-B1-ZW000.JPG
SomeFileName-B1-ZW000-1.JPG
SomeFileName-B1-ZW001.JPG
SomeFileName-B1-ZW002.JPG


Because of the slightly different names, the sorting is not correct.

Having hundreds of files like these. Do not want to change the name actually.

Wonder if it would be possible to fill the 'comment'-field with the last 3-4 digits, before the extension,
using a batch file.
(File-Properties-[tab]-Details)

Then I would be able to sort on comments, 000,001,001-1,002, etc.

Vainly tried to find something in ExifToolGUI.

Thanks!
-



Phil Harvey

Here is one way to do it:

exiftool "-comment<${filename;s/.*(\d{3}(-\d)?)\.[^.]*$/$1/}" DIR

(the above quoting is for Windows.  Use single quotes instead if you are on Mac or Linux.)

The regular expression above matches the pattern you specified just before the file extension, and copies this to the comment.  If the expression doesn't match, then the whole filename is copied.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

exwul

Thanks a lot.

I am afraid though nothing is happening.

See attached screenshot.



(exiftool is located on another partition, reason why I used the path:

F:\exiftool\exiftool "-comment<${filename;s/.*(\d{3,4}(-\d)?)\.[^.]*$/$1/}" DIR

hope you will have another look at it...??

Thanks!

-

Phil Harvey

"DIR" in the command was meant to represent the name of the directory containing the images (or "." for the current directory).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

exwul

When I use the   " . "   (without quotes) the results are as per screenshot

-

-
the regex is okay though...


Hayo Baan

My guess it that Phil's command worked, but the filelist in the explorer simply uses a different comment tag (XP-Comment perhaps?)
You can verify if Phil's command worked by having exiftool display the content of the comment tag:
exiftool -comment DIR_or_FILEs
To know which tag to set to have it shown in the windows explorer, fill the comment manually with some unique text, then run exiftool over it and look for the tag with that value. (Tip: If you run exiftool with the -s option, instead of descriptive names, exiftool will show you the tag names to use on the command line).

Hope this helps,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

Quote from: Hayo Baan on November 07, 2014, 10:49:12 AM
My guess it that Phil's command worked, but the filelist in the explorer simply uses a different comment tag (XP-Comment perhaps?)

You are correct, XPComment is the tag that explorer is reading.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

exwul

THANK you!

I should have used 'xpcomment' and the below worked out fine.

F:\exiftool\exiftool "-xpcomment<${filename;s/.*(\d{3,4}(-\d)?)\.[^.]*$/$1/}" .

=

=

Again, thank you very much indeed. It saves me a lot of work.

=