Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for isdev.bat

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

  1. @ECHO OFF
  2. :: Checks if %1 is a valid device name.
  3.  
  4. ECHO.
  5. IF "%1"=="" GOTO Syntax
  6. IF "%1"=="/?" GOTO Syntax
  7.  
  8. :: DOS or NT?
  9. VER | FIND "Windows NT" >NUL
  10. IF ERRORLEVEL 1 GOTO DOS
  11.  
  12. :NT
  13. :: Based on the fact that DIR doesn't show a volume label for devices
  14. DIR %1 2>NUL | FIND /I "Volume" >NUL
  15. IF     ERRORLEVEL 1 ECHO %1 is a valid NT device name
  16. IF NOT ERRORLEVEL 1 ECHO %1 is NOT a valid NT device name
  17. GOTO End
  18.  
  19. :DOS
  20. :: Based on the assumption that DIR displays
  21. :: no "file" date and time for devices.
  22. :: But first check AUX, CON and PRN, that are
  23. :: displayed with the current time and date.
  24. :: Sorry, this isn't a very elegant solution.
  25. :: If you know a better way, I'm all ears...
  26. SET OPATH=%PATH%
  27. PATH %1
  28. SET DEVICE=%PATH%
  29. PATH %OPATH%
  30. SET OPATH=
  31. IF "%DEVICE%"=="AUX" GOTO Valid
  32. IF "%DEVICE%"=="CON" GOTO Valid
  33. IF "%DEVICE%"=="PRN" GOTO Valid
  34. DIR \%DEVICE% | FIND "%DEVICE%" >NUL
  35. IF ERRORLEVEL 1 GOTO Invalid
  36. DIR \%DEVICE% | FIND "%DEVICE%" | FIND ":" >NUL
  37. IF NOT ERRORLEVEL 1 GOTO Invalid
  38. DIR \%DEVICE% | FIND "%DEVICE%" | FIND "." >NUL
  39. IF NOT ERRORLEVEL 1 GOTO Invalid
  40. DIR \%DEVICE% | FIND "%DEVICE%" | FIND "-" >NUL
  41. IF NOT ERRORLEVEL 1 GOTO Invalid
  42. DIR \%DEVICE% | FIND "%DEVICE%" | FIND "/" >NUL
  43. IF NOT ERRORLEVEL 1 GOTO Invalid
  44. :Valid
  45. ECHO.%DEVICE% is a valid device name
  46. GOTO End
  47. :Invalid
  48. ECHO.%DEVICE% is NOT a valid device name
  49. GOTO End
  50.  
  51. :Syntax
  52. ECHO IsDev,  Version 2.00 for NT and DOS
  53. ECHO Checks if the specified parameter is a valid device name
  54. ECHO.
  55. ECHO Usage:  ISDEV  device_name
  56.  
  57. :End
  58. SET DEVICE=
  59. ECHO.
  60.  

page last uploaded: 2017-04-06, 13:33