Automate chkdsk and defrag on your Windows XP PC.
This article shows you how to set up a batch file(script) to run to complete a disk check and defrag on your PC.
- Open Notepad.exe (Start Menu>Programs>Accessories>Notepad)
- Type or copy the code listed below (listing A) into Notepad
- Save the file as Dskchk.cmd
- Create another text file called DrvLtr.txt and list the letters of the drives you want checked, with each letter on its own line (see example in listing B). Type "End" on the last line.
- Put Dskchk.cmd and DrvLtr.txt in the same directory (for example c:\Maintenance)
- You can run the script by navigating to the directory you saved the files in and double clicking on Dskchk.cmd file.
- You can set this to run on a schedule by using the Windows XP Task Scheduler. (Start Menu>Control Panel>Scheduled Tasks) Create a new task and browse to the Dskchk.cmd file. Choose the desired schedule. I would recommend once a week, depending on how you use your PC.
- Listing A (Dskchk.cmd)
REM chkdsk and defrag automation
for /F "eol= tokens=1 delims=( " %%i in (DrvLtr.txt) do set DrvLtr=%%i% call
:dskChk
:dskChk
if %DrvLtr% == end goto :eof
chkdsk %DrvLtr%
if not errorlevel 3 goto :defrag
if not exist %DrvLtr%\winnt If not exist %DrvLtr\windows if not exist
%DrvLtr%\pagefile.sys goto :dskchkon
:cd\
%DrvLtr%
echo Y chkdsk /F /R
goto :defrag
:defrag
cd\
%DrvLtr%
defrag %DrvLtr% -b
defrag %DrvLtr%
:EOF
- Listing B (DrvLtr.txt)
C:
D:
end






