Rename 1,000's of Files Based on MIME Type

Started by EverdarkOmnis, March 26, 2025, 06:18:42 PM

Previous topic - Next topic

EverdarkOmnis

Rename 1,000's of Files Based on MIME Type?

Ok, so I messed up and renamed every file in multiple folders ".jpg" ... DOH !!!

Renaming manually has ben slow and tedious.

I've looked at several exif commmand line examples but nothing matches what I am looking for. I found one but while researching all the MIME Types i lost link to script details.

What I need is a simple script that changes the extension of every file and sub-folder files based upon mime types

if MIMETYPE = "image/jpeg" rename FILENAME.EXTENSION

"image/jpeg"         = ".jpg"
"image/png"         = ".png"
"image/webp"         = ".webp"
"image/gif"         = ".gif"
"image/x-xcf"         = ".xcf"
"image/svg+xml"         = ".svg"
"image/bmp"         = ".bmp"

"text/plain"         = ".txt"
"text/html"         = ".html"

"application/postscript"   = ".eps"
"application/pdf"      = ".pdf"
"application/octet-stream"   = ".lnk"
"application/zip"      = ".zip"
"application/x-rar-compressed"   = ".rar"
"application/vnd.oasis.opendocument.graphics"   = ".odg"

"video/mp4"         = ".mp4"
"video/3gpp"         = ".3gp"
"video/x-matroska"      = ".mkv"
"video/x-msvideo"      = ".avi"


Thank you, in advance.

Phil Harvey

This should get you most of the way there:

exiftool "-filename<%f.$filetypeextension" -v DIR

I've added the -v so you will have a record of what happened.

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

EverdarkOmnis

Quote from: Phil Harvey on March 26, 2025, 08:57:15 PMThis should get you most of the way there:

exiftool "-filename<%f.$filetypeextension" -v DIR

I've added the -v so you will have a record of what happened.

- Phil

thx Phil, i'll give it a shot

EverdarkOmnis

Quote from: Phil Harvey on March 26, 2025, 08:57:15 PMThis should get you most of the way there:

exiftool "-filename<%f.$filetypeextension" -v DIR

I've added the -v so you will have a record of what happened.

- Phil


mimeExt.ps1
"C:\Portable Program Files\exiftool\exiftool.exe" "-filename<%f.$filetypeextension" -v "F:\Sync\Knowledge\History\.United States of America\New York City NY\Grand Central Terminal"

PS F:\Sync\Development\PowershellScripts> .\mimeExt.ps1

This was the output...
At F:\Sync\Development\PowershellScripts\mimeExt.ps1:1 char:51
+ ... iles\exiftool\exiftool.exe" "-filename<%f.$filetypeextension" -v "F:\ ...
+                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '"-filename<%f.$filetypeextension"' in expression or statement.
At F:\Sync\Development\PowershellScripts\mimeExt.ps1:1 char:85
+ ... s\exiftool\exiftool.exe" "-filename<%f.$filetypeextension" -v "F:\Syn ...
+                                                                ~~
Unexpected token '-v' in expression or statement.
At F:\Sync\Development\PowershellScripts\mimeExt.ps1:1 char:88
+ ... tension" -v "F:\Sync\Knowledge\History\.United States of America\New  ...
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '"F:\Sync\Knowledge\History\.United States of America\New York City NY\Grand Central Terminal"' in
expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

Phil Harvey

This is entirely a problem with your PS script.  I don't know PS and don't recommend using it so I can't help here.

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