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.
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
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
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
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
Don't use PowerShell unless you are willing to figure out its syntax, which is different from every other command line. I gave up on it long ago.
Some example problems
PowerShell quoting (https://exiftool.org/forum/index.php?msg=80581)
PowerShell corrupts binary data (https://exiftool.org/forum/index.php?msg=41663)
PowerShell requires decimal values to be quoted
PS C:\> exiftool -P -overwrite_original -Description=9.9 y:\!temp\Test4.jpg
Error: File not found - .9
1 image files updated
1 files weren't updated due to errors
PS C:\> exiftool -G1 -a -s -Description y:\!temp\Test4.jpg
[XMP-dc] Description : 9