Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for listverbs.bat

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

  1. @ECHO OFF
  2. IF     "%~1"=="" GOTO Syntax
  3. IF NOT "%~2"=="" GOTO Syntax
  4. ECHO.%* | FIND.EXE "?" >NUL && GOTO Syntax
  5. ECHO.%~1| FINDSTR.EXE /R /X /C:"\.[a-z0-9][a-z0-9]*" >NUL || GOTO Syntax
  6.  
  7. SETLOCAL ENABLEDELAYEDEXPANSION
  8. SET ColumnWidth=0
  9. SET RC=0
  10. FOR /F "tokens=2 delims==" %%A IN ('ASSOC "%~x1"') DO (
  11. 	ECHO Extension = %1
  12. 	ECHO File Type = %%A
  13. 	ECHO Verbs:
  14. 	FOR /F "tokens=1-4* delims=\" %%C IN ('REG Query HKCR\%%~A\shell') DO (
  15. 		SET /A RC += 1
  16. 		CALL :GetMaxStringLength ColumnWidth "%%~F"
  17. 	)
  18. 	FOR /F "tokens=1-4* delims=\" %%C IN ('REG Query HKCR\%%~A\shell') DO (
  19. 		FOR /F "tokens=2*" %%G IN ('REG Query "%%~C\%%~D\%%~E\%%~F\command" ^| FIND /V "HKEY_"') DO (
  20. 			REM Append 40 spaces after verb name
  21. 			SET Column=%%F                                        
  22. 			REM Chop at maximum column width
  23. 			FOR %%I IN (!ColumnWidth!) DO SET Column=!Column:~0,%%I!
  24. 			ECHO 	!Column!        %%H
  25. 		)
  26. 	)
  27. )
  28. ENDLOCAL & EXIT /B %RC%
  29.  
  30.  
  31. :GetMaxStringLength
  32. :: Usage : GetMaxStringLength OutVariableName StringToBeMeasured
  33. :: Note  : OutVariable may already have an initial value
  34. SET StrTest=%~2
  35. SET /A %1 += 0
  36. FOR /L %%A IN (!%1!,1,40) DO (
  37. 	IF NOT "!StrTest:~%%A!"=="" (
  38. 		SET /A %1 = %%A + 1
  39. 	)
  40. )
  41. GOTO:EOF
  42.  
  43.  
  44. :Syntax
  45. ECHO.
  46. ECHO ListVerbs.bat,  Version 1.00 for Windows
  47. ECHO List all verbs for the specified file extension
  48. ECHO.
  49. ECHO Usage:  ListVerbs.bat   fileextension
  50. ECHO.
  51. ECHO Where:  fileextension   is the file extension to list the
  52. ECHO                         available verbs for e.g. ".odt"
  53. ECHO.
  54. ECHO Note:   Return code ("errorlevel") equals the number of verbs
  55. ECHO         found, or -1 in case of (command line) errors.
  56. ECHO.
  57. ECHO Written by Rob van der Woude
  58. ECHO https://www.robvanderwoude.com
  59. EXIT /B -1
  60.  

page last uploaded: 2021-01-27