rename files based on MIME type

Started by c_bechmann, June 15, 2020, 05:30:15 PM

Previous topic - Next topic

c_bechmann

Hi.

TL: DR
I need to rename 10.000+ files based on their MIME-type, so they have the right extension.



Long read:
Hi, newbie here.

I am helping my friend moving data from one database to another. For that, he has a load of images (10.000+) which needs to be sorted by file type (jpg, png and TGA).

Problem is, that the files are only available without file-extensions. They are all named "productserial.angle", angle being a number between 1 and 3, eg. "05047294014.1". I would like this to become "05047294014.1.jpg" (if it is a jpg, of course)

The new database only accepts jpeg-encoded files, so I need some way to sort the three file types. Therefore, my best idea would be to use ExifTool to read the MIME type and then append the correct extension or another unique identifier.

Is this possible? I still remember my way around the command prompt, but the command-line options for ExifTool seem to be above my current level, at least for the time being.

Thanks for any help!

StarGeek

Take a look at this thread.  If you're on Windows, change the single quotes to double quotes.
* 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).

c_bechmann

#2
Hey StarGeek.
It worked just perfect.

I ended up giving the images an "extra" extension (05047294014.1 -> 05047294014.1.bob) using http://www.1-4a.com/rename/, so ExifTool had an non-significant extension to replace.

Then I ran your string:
exiftool -ext '*' '-FileName<%f.$FileTypeExtension' -r DIR/

ExifTool couldn't identify my TGA's, and a few of the images were self-identifying as MP3 (?). Nevertheless, it was only ~15 out of 15.000 needing special care.

Thanks for your help!

Phil Harvey

Quote from: c_bechmann on June 23, 2020, 12:45:22 PM
I ended up giving the images an "extra" extension (05047294014.1 -> 05047294014.1.bob) using http://www.1-4a.com/rename/, so ExifTool had an non-significant extension to replace.

Then I ran your string:
exiftool -ext '*' '-FileName<%f.$FileTypeExtension' -r DIR/

You could have done this

exiftool -ext '*' '-FileName<%f.%e.$FileTypeExtension' -r DIR/

If you just wanted to add the extension and leave existing extensions.

QuoteExifTool couldn't identify my TGA's, and a few of the images were self-identifying as MP3 (?). Nevertheless, it was only ~15 out of 15.000 needing special care.

ExifTool doesn't support TGA, and the magic is weak for MP3 so false positives are very possible.

- 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 ($).