BrianHawkinsTech

  • Increase font size
  • Default font size
  • Decrease font size
Home Hardware Automate Chkdsk and Defrag on Windows XP

Automate Chkdsk and Defrag on Windows XP

E-mail Print PDF

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.

  1. Open Notepad.exe (Start Menu>Programs>Accessories>Notepad)
  2. Type or copy the code listed below (listing A) into Notepad
  3. Save the file as Dskchk.cmd
  4. 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.
  5. Put Dskchk.cmd and DrvLtr.txt in the same directory (for example c:\Maintenance)
  6. You can run the script by navigating to the directory you saved the files in and double clicking on Dskchk.cmd file.
  7. 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
 

Recommended Web Hosting


Free Stuff!

Featured FREE Resource:

Featured FREE Resource: