PDA

View Full Version : BAT file


evildragon
April 21st, 2008, 06:22 PM
I can't seem to find how to do this.. Tried searching but got nowhere.

I have all of my autoexec.bat commands go to my D: drive, as my D: drive is where everything is.

Though, sometimes I may not want my D: drive on (it's an external), and instead of my computer booting saying a crap load of Bad command or file names, and Invalid Directory, I want autoexec.bat to first check for the presense of the D: drive.

If the d: drive is there, then it can go on, but if it's not there, I want it to just end auto exec immediately.

EDIT: I tried for this one, but it seems to be for if the drive already has a letter, but no disk.. Mine either has a letter or not.
http://snippets.dzone.com/posts/show/4141

ahm
April 21st, 2008, 07:27 PM
Try this:

@echo off
ctty nul
%comspec% /f /c dir d: | find "Directory of "
ctty con
if errorlevel==0 if not errorlevel==1 goto _isready
echo Drive D: is NOT ready
goto _end
::
:_isready
echo Drive D: is ready
goto _end
::
:_end

Timo Salmi's BATCH Tricks is an excellent read.
http://lipas.uwasa.fi/~ts/http/http2.html, search for "tsbat.zip"

Terry Yager
April 21st, 2008, 08:55 PM
I like Andy's solution, but how bout:

IF EXIST D:\
D:\AUTOEXEC.BAT

(Worth a try).

--T

evildragon
April 21st, 2008, 11:49 PM
I like Andy's solution, but how bout:

IF EXIST D:\
D:\AUTOEXEC.BAT

(Worth a try).

--T
This one would boot and work if the drive was on, but if the drive was off, it would then say "Invalid drive specification" then show the C: prompt.

I'm going to try the other one.

Try this:

@echo off
ctty nul
%comspec% /f /c dir d: | find "Directory of "
ctty con
if errorlevel==0 if not errorlevel==1 goto _isready
echo Drive D: is NOT ready
goto _end
::
:_isready
echo Drive D: is ready
goto _end
::
:_end

Timo Salmi's BATCH Tricks is an excellent read.
http://lipas.uwasa.fi/~ts/http/http2.html, search for "tsbat.zip"
Even though the most complicated batch file I ever used, it not only worked great, but I understood it too. I put all important loads in the D: drive area, and put DATE/TIME past the end. So either way, it asks for date and time, and if the drive is there, it loads what's on it. (and put the HD enclosures driver before the whole thing).

Thanks.

ahm
April 22nd, 2008, 02:05 PM
how bout:

IF EXIST D:\
D:\AUTOEXEC.BAT



You'd probably need to change that to something like this:
IF EXIST D:\NUL CALL D:\AUTOEXEC.BAT

Andy