Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for mimetype.bat

(view source code of mimetype.bat as plain text)

  1. @ECHO OFF
  2. IF     "%~1"=="" GOTO Syntax
  3. IF NOT "%~2"=="" GOTO Syntax
  4. IF     "%~1"=="/?" GOTO Syntax
  5. IF /I  "%~1"=="/L" GOTO ListAll
  6. ECHO "%~1" | FINDSTR.EXE /R /X /I /C:"\""*[a-z\.][a-z\./\-]*\""* *" >NUL || GOTO Syntax
  7.  
  8. SETLOCAL ENABLEDELAYEDEXPANSION
  9. SET Param="%~1"
  10. IF "%Param:~1,1%"=="." (
  11. 	SET Found=0
  12. 	FOR /F "tokens=1,5 delims=\" %%A IN (' REG.EXE Query "HKEY_CLASSES_ROOT\MIME\Database\Content Type" /s /f "Extension"') DO (
  13. 		IF "%%~B"=="" (
  14. 			FOR /F "tokens=1,3" %%C IN ("%%~A") DO (
  15. 				IF /I "%%~C"=="Extension" (
  16. 					IF /I "%%~D"=="%~1" (
  17. 						ECHO %~1	!MimeType!
  18. 					)
  19. 				)
  20. 			)
  21. 		) ELSE (
  22. 			SET MimeType=%%B
  23. 		)
  24. 	)
  25. ) ELSE (
  26. 	FOR /F "tokens=3" %%A IN ('REG.EXE Query "HKEY_CLASSES_ROOT\MIME\Database\Content Type\%~1" /v "Extension" ^| FIND.EXE "REG_SZ"') DO (
  27. 		ECHO %%A	%~1
  28. 	)
  29. )
  30. ENDLOCAL
  31. GOTO:EOF
  32.  
  33.  
  34. :ListAll
  35. SETLOCAL ENABLEDELAYEDEXPANSION
  36. FOR /F "tokens=1,5 delims=\" %%A IN (' REG.EXE Query "HKEY_CLASSES_ROOT\MIME\Database\Content Type" /s /f "Extension"') DO (
  37. 	IF "%%~B"=="" (
  38. 		FOR /F "tokens=1,3" %%C IN ("%%~A") DO (
  39. 			IF /I "%%~C"=="Extension" (
  40. 				ECHO %%~D	!MimeType!
  41. 			)
  42. 		)
  43. 	) ELSE (
  44. 		SET MimeType=%%B
  45. 	)
  46. )
  47. ENDLOCAL
  48. GOTO:EOF
  49.  
  50.  
  51. :Syntax
  52. ECHO.
  53. ECHO MimeType.bat,  Version 1.00 for Windows 10
  54. ECHO Find the registered mime type for a specified file extension or vice versa
  55. ECHO.
  56. ECHO Usage:     MimeType.bat  [ mimetype ^| extension ^| /L ]
  57. ECHO.
  58. ECHO Where:     /L    will display a list of all registered combinations
  59. ECHO.
  60. ECHO Examples:  MimeType.bat .ogg
  61. ECHO            MimeType.bat video/ogg
  62. ECHO.           both commands will return something like: .ogg    video/ogg
  63. ECHO.
  64. ECHO Written by Rob van der Woude
  65. ECHO https://www.robvanderwoude.com
  66. EXIT /B 1
  67.  

page last modified: 2024-04-16; loaded in 0.0079 seconds