Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

basic batch drive presence check (See related posts)

// check if removable drives are present. useful with batch backups and letter-jumping flash drives.
// floppies (a:, b:) can cause screen flash asking for floppy to be inserted.
//
// two batch files required - 1. foo.bat
@echo off
echo simple drive check > %temp%\tmp.txt
echo. >> %temp%\tmp.txt
for %%a in (c:, d:, e:, f:, g:) do call bar.bat %%a
cls
type %temp%\tmp.txt
echo.

// 2. bar.bat
%comspec% /f /c vol %1 | find /c "Vol" | choice /c:210
if not errorlevel 2 if errorlevel 1 echo %1 present >> %temp%\tmp.txt
if not errorlevel 3 if errorlevel 2 echo %1 not present >> %temp%\tmp.txt

// screen output can be suppressed by wrapping
ctty nul
for %%a in (c:, d:, e:, f:, g:) do call bar.bat %%a
ctty con

// in foo.bat

You need to create an account or log in to post comments to this site.


Click here to browse all 5137 code snippets

Related Posts