Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cdactxp.bat

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

  1. @ECHO OFF
  2. :: Check Windows version and command line arguments
  3. IF NOT "%OS%"=="Windows_NT"  GOTO Syntax
  4. IF NOT "%~1"==""             GOTO Syntax
  5. DISKPART.EXE /? >NUL 2>&1 || GOTO Syntax
  6.  
  7. :: Localize variable and enable delayed variable expansion
  8. SETLOCAL ENABLEDELAYEDEXPANSION
  9. SET CDACT=
  10. SET Multi=
  11.  
  12. :: The actual command
  13. FOR /F "tokens=3" %%A IN ('ECHO list volume ^| DISKPART.EXE ^| FIND.EXE " CDFS "') DO (
  14. 	IF DEFINED CDROM (
  15. 		SET CDACT=!CDACT! %%A
  16. 		SET Multi=s
  17. 	) ELSE (
  18. 		SET CDACT=%%A
  19. 	)
  20. )
  21.  
  22. :: Display the result
  23. IF DEFINED CDACT (
  24. 	ECHO CD/DVD found in drive%Multi% %CDACT%
  25. ) ELSE (
  26. 	ECHO No CDs/DVDs found in any drive
  27. )
  28.  
  29. :: Done
  30. ENDLOCAL & SET CDACT=%CDACT%
  31. GOTO:EOF
  32.  
  33.  
  34. :Syntax
  35. ECHO CDACTXP.BAT,  Version 1.00 for Windows XP
  36. ECHO Find all CD/DVD-ROM drives containing a CD/DVD-ROM using Windows' DISKPART
  37. ECHO.
  38. ECHO Usage:  CDACTXP
  39. ECHO.
  40. ECHO A list of all CD/DVD-ROM drives actually containing a disk will be
  41. ECHO stored in the environment variable CDACT.
  42. ECHO This batch file will fail if any non-CD/DVD volume is labeled "CDFS".
  43. ECHO.
  44. ECHO Written by Rob van der Woude
  45. ECHO http://www.robvanderwoude.com
  46.  
  47. :: Done
  48. IF "%OS%"=="Windows_NT" GOTO:EOF
  49.  

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