Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for chkpath.bat

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

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: Check command line arguments
  6. IF NOT "%~2"=="" GOTO Syntax
  7. IF NOT "%~1"=="" IF /I NOT "%~1"=="/Q" IF /I NOT "%~1"=="/V" GOTO Syntax
  8.  
  9. :: Check if WMIC.EXE is available
  10. WMIC.EXE /? >NUL 2>&1 || GOTO Syntax
  11.  
  12. :: Enable delayed variable expansion
  13. SETLOCAL ENABLEDELAYEDEXPANSION
  14.  
  15. :: Initialize variables
  16. SET ChkPath=%Path:"=%
  17. SET Error=0
  18.  
  19. IF /I "%~1"=="/V" (
  20. 	ECHO.
  21. 	ECHO Full Path:
  22. 	ECHO.==========
  23. 	PATH
  24. 	ECHO.
  25. 	ECHO System Path:
  26. 	ECHO.============
  27. 	WMIC.EXE Path Win32_Environment Where "Name='PATH' And Systemvariable=TRUE"  Get VariableValue 2>NUL | FIND ":\" || ECHO -- empty --
  28. 	ECHO.
  29. 	ECHO User Path:
  30. 	ECHO.==========
  31. 	WMIC.EXE Path Win32_Environment Where "Name='PATH' And Systemvariable=FALSE" Get VariableValue 2>NUL | FIND ":\" || ECHO -- empty --
  32. 	ECHO.
  33. 	ECHO Check All Entries:
  34. 	ECHO.==================
  35. )
  36.  
  37. :: Check the first PATH entry, and remove it from the temporary path variable
  38. :Loop
  39. FOR /F "tokens=1* delims=;" %%A IN ("!ChkPath!") DO (
  40. 	IF EXIST %%A.\ (
  41. 		IF /I NOT "%~1"=="/Q" ECHO OK	%%A
  42. 	) ELSE (
  43. 		ECHO ERROR:	%%A
  44. 		SET Error=1
  45. 	)
  46. 	SET ChkPath=%%B
  47. )
  48. :: Repeat until there are no more PATH enries left
  49. IF NOT "%ChkPath%"=="" GOTO Loop
  50.  
  51. :: Exit with return code
  52. ENDLOCAL & EXIT /B %Error%
  53.  
  54.  
  55. :Syntax
  56. ECHO.
  57. ECHO ChkPath.bat,  Version 2.00 for Windows 7 and later
  58. ECHO Verify if all PATH entries are valid directories
  59. ECHO.
  60. ECHO Usage:  CHKPATH  [ /Q ^| /V ]
  61. ECHO.
  62. ECHO Where:             /Q    lists errors only (default: all entries)
  63. ECHO                    /V    lists full PATH variables as well
  64. ECHO.
  65. ECHO Written by Rob van der Woude
  66. ECHO http://www.robvanderwoude.com
  67.  

page last uploaded: 2016-12-15, 11:20