(view source code of mimetype.bat as plain text)
@ECHO OFF
IF "%~1"=="" GOTO Syntax
IF NOT "%~2"=="" GOTO Syntax
IF "%~1"=="/?" GOTO Syntax
IF /I "%~1"=="/L" GOTO ListAll
ECHO "%~1" | FINDSTR.EXE /R /X /I /C:"\""*[a-z\.][a-z\./\-]*\""* *" >NUL || GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
SET Param="%~1"
IF "%Param:~1,1%"=="." (
SET Found=0
FOR /F "tokens=1,5 delims=\" %%A IN (' REG.EXE Query "HKEY_CLASSES_ROOT\MIME\Database\Content Type" /s /f "Extension"') DO (
IF "%%~B"=="" (
FOR /F "tokens=1,3" %%C IN ("%%~A") DO (
IF /I "%%~C"=="Extension" (
IF /I "%%~D"=="%~1" (
ECHO %~1 !MimeType!
)
)
)
) ELSE (
SET MimeType=%%B
)
)
) ELSE (
FOR /F "tokens=3" %%A IN ('REG.EXE Query "HKEY_CLASSES_ROOT\MIME\Database\Content Type\%~1" /v "Extension" ^| FIND.EXE "REG_SZ"') DO (
ECHO %%A %~1
)
)
ENDLOCAL
GOTO:EOF
:ListAll
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1,5 delims=\" %%A IN (' REG.EXE Query "HKEY_CLASSES_ROOT\MIME\Database\Content Type" /s /f "Extension"') DO (
IF "%%~B"=="" (
FOR /F "tokens=1,3" %%C IN ("%%~A") DO (
IF /I "%%~C"=="Extension" (
ECHO %%~D !MimeType!
)
)
) ELSE (
SET MimeType=%%B
)
)
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO MimeType.bat, Version 1.00 for Windows 10
ECHO Find the registered mime type for a specified file extension or vice versa
ECHO.
ECHO Usage: MimeType.bat [ mimetype ^| extension ^| /L ]
ECHO.
ECHO Where: /L will display a list of all registered combinations
ECHO.
ECHO Examples: MimeType.bat .ogg
ECHO MimeType.bat video/ogg
ECHO. both commands will return something like: .ogg video/ogg
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0079 seconds