DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Basic Batch Drive Presence Check

  • submit to reddit
        // 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
type %temp%\tmp.txt
// 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