>If you want my entire check.bat and the batch enhancer, drop me a note and
>I'll send it (if too many requests, I'll post instead).
I'm going to be away for a week so rather than have people wait I'm posting
now. After re-reading my original follow-up (shown above) I see that I made
a misleading statement about sending the batch enhancer. I meant I would
send a pointer to the enhancer along with the check.bat file. Sorry.
The following is my batch file CHECK.BAT which runs ChkDsk periodically.
If it is time to run ChkDsk, the batch program does so without the /f
parameter (I expect that most of the time there will not be any errors).
If no errors are found, CHECK.BAT ends and returns to the batch file that
called it (autoexec.bat). If errors are found, you will be prompted to
run ChkDsk again, this time with the /f parameter set. Why do it this way?
Because sometimes I'm in a hurry and don't feel like waiting for another
round of ChkDsk. Now that I think about it, why didn't I simply run
ChkDsk /f the first time? Oh, now I remember, because several people
use the same computer, and may be somewhat intimidated by the various
error messages given by ChkDsk with the /f parameter set. For this
reason the option not to do anything is given. If your situation is the
same, you can use the file as given, otherwise simply delete everything
after line 7 "chkdsk | find ..." except the lines "SET GET=" and
"chkdsk /f" .
(My apologies to the original poster who wanted a conditional pause or
escape from his autoexec.bat if chkdsk failed, which I assume means an
error was found--my original lengthy answer to his question was
probably unnecessary, since all that was really needed was to add the
/f parameter to his chkdsk line.)
The example below is set to run ChkDsk once a month. If a once-a-week
frequency is desired, make the following changes:
1) remove line 2 "if exist ..." and line 5 "echo SET MONTH=%GET% ..."
2) change line 3 "GET H 4" to "GET H 1"
3) change line 4 "if %GET%==%MONTH% ..." to "if not %GET%==3 goto Noerrors
4) remove the last line "SET MONTH="
Change number 3) above will cause ChkDsk to run every Wednesday.
For a daily run of ChkDsk that will allow corrections before starting
other programs in the autoexec.bat file, simply remove lines 2 through 7
and the last line.
if exist C:\tools\month.bat call C:\tools\month.bat
GET H 4
if %GET%==%MONTH% goto NoErrors
echo SET MONTH=%GET% > C:\tools\month.bat
echo.
echo Time for the monthly disk errors check . . .
chkdsk | find "Errors found" > C:\errors.fnd
copy C:\errors.fnd C:\errors.chk > nul
del C:\errors.fnd > nul
if exist C:\errors.chk goto ErrFound
goto NoErrors
:ErrFound
del C:\errors.chk > nul
echo.
set GET=
GET NE "Errors were found. Do you want them corrected (Y or N)? "
if %GET%==N goto NoErrors
echo.
chkdsk /f
echo.
:Noerrors
echo.
set GET=
set MONTH=
NOTE:
1) There is no need to create MONTH.BAT since CHECK.BAT creates it for you.
2) You can change the path for MONTH.BAT to anything you wish, as long as
it exists, and as long as all occurrences of C:\tools\month.bat are
changed to the same thing.
3) In the batch program shown, the GET program is in a directory in my path.
You must do the same, or otherwise include the path when running GET
4) MOST IMPORTANT: OBTAIN GET24.ZIP from your favorite ftp site. I found it
at oak.oakland.edu in pub\msdos\batutl. If you enjoy monkeying with
batch files, this is certainly an excellent program to have.
5) insert the line "call check.bat" (no quotes) into your AUTOEXEC.BAT file
in an appropriate position. I put mine before I run Windows since ChkDsk
should not be run while in the Windows environment. If CHECK.BAT is not
in a directory on your path, then include the path.
Darren Natale