Many people need to be sure a disk is inserted (or not) into the A: drive to prevent their batch files from crashing. The following code accomplishes that. It uses the undocumented "/f" option of COMMAND.COM (see http://www.ericphelps.com/batch/tricks/index.htm#abort ) to do it. You'll see several lines that say "insert code here". So you should. Tricks used include using "ctty nul" and "> nul" to hide error and other messages, using %%"%% to allow the redirection of redirection characters (see http://www.ericphelps.com/batch/secondry/index.htm ), and testing for the existence of a device (like CON, NUL, COM1, PRN, etc.) on a disk to see if the disk exists. I show how to insure a disk exists, how to check for write protection, how to check for a blank disk, and finally how to insure NO disk is in the A: drive. At the very end, I show another technique that uses a separate utility like PKZIP to check for a disk in the A drive. FYI, the CHOICE command is not generally available under NT. You can get it on the disk version of the Resource Kit, but not on the download version. If you really want to implement this Win9x solution on NT, you can always steal a copy of CHOICE.EXE from a Win9x box. All reports I've heard say it works just fine. If a Win98 box isn't handy, download it: ftp://ftp.microsoft.com/Services/TechNet/samples/PS/Win98/Reskit/SCRPTING/ ------------------------------------------------------------- @echo off :ISDISKIN echo if exist a:\nul goto OKAY > checkdisk.bat echo goto NOTOKAY >> checkdisk.bat echo :NOTOKAY >> checkdisk.bat echo if exist ~exist.txt del ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :OKAY >> checkdisk.bat echo rem%%"%%>%%"%% ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :DONE >> checkdisk.bat ctty nul command /f /c checkdisk.bat ctty con del checkdisk.bat if not exist ~exist.txt goto NODISK del ~exist.txt > nul goto PROCESS :NODISK cls echo Insert a disk in the A: drive and press "y" when ready. choice /cyn /n Press "n" to cancel. if errorlevel 2 goto CANCEL goto ISDISKIN :CANCEL cls echo Insert your code here for what happens if the user cancels goto DONE :PROCESS echo Insert your code here needing the A: drive goto DONE :DONE ------------------------------------------------------------- Note that the above code only checks to see if a floppy exists. If you need to write to the floppy, you'll want to add code to check to see if it is write-protected (like shown below) in the PROCESS section: ------------------------------------------------------------- echo rem%%"%%>%%"%% a:\~test.txt > checkdisk.bat echo if exist a:\~test.txt goto OKAY >> checkdisk.bat echo goto NOTOKAY >> checkdisk.bat echo :NOTOKAY >> checkdisk.bat echo if exist ~exist.txt del ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :OKAY >> checkdisk.bat echo del a:\~test.txt%%"%%>%%"%% nul >> checkdisk.bat echo rem%%"%%>%%"%% ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :DONE >> checkdisk.bat ctty nul command /f /c checkdisk.bat ctty con del checkdisk.bat if not exist ~exist.txt goto WRITEPRO del ~exist.txt > nul goto NOTPROT :WRITEPRO cls echo The disk in the A: drive is write-protected. echo Please unprotect the disk and press "y" when ready. choice /cyn /n Press "n" to cancel. if errorlevel 2 goto CANCEL goto ISDISKIN :NOTPROT echo Insert code here needing a non-write-protected disk goto DONE ------------------------------------------------------------- Then it gets worse. Suppose you need a BLANK disk in the A: drive. Insert code like shown below in the NOTPROT section: ------------------------------------------------------------- dir /s /b a:\ | find "\" > nul if not errorlevel 1 goto NOTBLANK goto ISBLANK :NOTBLANK cls echo The disk in the A: drive is not blank. echo Please replace the disk with a blank echo one and press "y" when ready. choice /cyn /n Press "n" to cancel. if errorlevel 2 goto CANCEL goto ISDISKIN :ISBLANK echo Insert code here needing a blank disk goto DONE ------------------------------------------------------------- Here's the end result: All the above code in one piece. It checks to see that a disk exists, that it isn't write protected, and that it is blank: ------------------------------------------------------------- @echo off :ISDISKIN echo if exist a:\nul goto OKAY > checkdisk.bat echo goto NOTOKAY >> checkdisk.bat echo :NOTOKAY >> checkdisk.bat echo if exist ~exist.txt del ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :OKAY >> checkdisk.bat echo rem%%"%%>%%"%% ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :DONE >> checkdisk.bat ctty nul command /f /c checkdisk.bat ctty con del checkdisk.bat if not exist ~exist.txt goto NODISK del ~exist.txt > nul goto PROCESS :NODISK cls echo Insert a disk in the A: drive and press "y" when ready. choice /cyn /n Press "n" to cancel. if errorlevel 2 goto CANCEL goto ISDISKIN :CANCEL cls echo Insert your code here for what happens if the user cancels goto DONE :PROCESS echo rem%%"%%>%%"%% a:\~test.txt > checkdisk.bat echo if exist a:\~test.txt goto OKAY >> checkdisk.bat echo goto NOTOKAY >> checkdisk.bat echo :NOTOKAY >> checkdisk.bat echo if exist ~exist.txt del ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :OKAY >> checkdisk.bat echo del a:\~test.txt%%"%%>%%"%% nul >> checkdisk.bat echo rem%%"%%>%%"%% ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :DONE >> checkdisk.bat ctty nul command /f /c checkdisk.bat ctty con del checkdisk.bat if not exist ~exist.txt goto WRITEPRO del ~exist.txt > nul goto NOTPROT :WRITEPRO cls echo The disk in the A: drive is write-protected. echo Please unprotect the disk and press "y" when ready. choice /cyn /n Press "n" to cancel. if errorlevel 2 goto CANCEL goto ISDISKIN :NOTPROT dir /s /b a:\ | find "\" > nul if not errorlevel 1 goto NOTBLANK goto ISBLANK :NOTBLANK cls echo The disk in the A: drive is not blank. echo Please replace the disk with a blank echo one and press "y" when ready. choice /cyn /n Press "n" to cancel. if errorlevel 2 goto CANCEL goto ISDISKIN :ISBLANK cls echo Insert code here needing a blank disk goto DONE :DONE ------------------------------------------------------------- Here's just the opposite. Now I'll show code that refuses to proceed unless you REMOVE the disk from the A: drive. ------------------------------------------------------------- @echo off :: Checks for a disk in the A: drive and will :: refuse to proceed until the disk is removed. :: Place any code you want at the end of this :: batch file (after the NODISK label). :ISDISKIN echo if exist a:\nul goto OKAY > checkdisk.bat echo goto NOTOKAY >> checkdisk.bat echo :NOTOKAY >> checkdisk.bat echo if exist ~exist.txt del ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :OKAY >> checkdisk.bat echo rem%%"%%>%%"%% ~exist.txt >> checkdisk.bat echo goto DONE >> checkdisk.bat echo :DONE >> checkdisk.bat ctty nul command /f /c checkdisk.bat ctty con del checkdisk.bat if not exist ~exist.txt goto NODISK :DISK del ~exist.txt > nul echo Remove the disk in the A: drive and press any key when ready. pause>nul goto ISDISKIN :NODISK ------------------------------------------------------------- Here I will show a way to use PKZIP to check if a writable disk is in the A drive. You can substitute any other program you might have. All you have to do is find a program that WON'T lock your computer up if the A drive has no disk or has a write-protected disk. Then you have to hope that program will return a usable error message or errorlevel! ------------------------------------------------------------- @echo off pkzip a:\zzz.zip nul>nul if errorlevel 1 goto NODISK del a:\zzz.zip > nul goto GOTDISK :NODISK echo You didn't insert a writable disk! goto DONE :GOTDISK echo You put a writable disk in! Good dog! goto DONE :DONE ------------------------------------------------------------- :: http://www.ericphelps.com