SEARCH

How-To Geek

Defrag Multiple Hard Drives At Once In Windows

The Disk Defragment utility in Windows XP does not include a way to defragment all hard drives at the same time, which is inconvienient when you have more than one hard drive in your computer.

The method we are going to use is by creating a batch file to defragment all of the drives, one after the other.

The disk defrag utility in Windows XP can be triggered from the command line with the following syntax:

Windows Disk Defragmenter
Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.
Usage:
defrag <volume> [-a] [-f] [-v] [-?]
  volume  drive letter or mount point (d: or d:\vol\mountpoint)
  -a      Analyze only
  -f      Force defragmentation even if free space is low
  -v      Verbose output
  -?      Display this help text

First, we’ll create a file named defragall.bat, and place it anywhere you like, as long as you’ll remember where it is. If you want to run it from the command line, you could place it in the \windows directory so that it will be available in the system path.

For each hard drive, add a line to the batch file. For instance, if we want to defragment drives C: , D: , and F: we will add these three lines:

defrag c: -f
defrag d: -f
defrag f: -f

To run the defrag, just either double-click on the batch file or start it from the command line.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 11/22/06

Comments (18)

  1. jkugler

    I have already done this but was wondering if there is a way to not show the command line box when the batch is exicuted or atleast start it minimized? Any help would be a appreciated. Tthank You in advance.

  2. visitor

    @echo off

  3. Dean

    Thanks. This is truly an eye opener….

  4. Tie 1 On

    I have made the Defrag batch file, but i’m not sure if it’s working properly. Is there any way of seeing the progress of the defrag?

  5. Rajagopalan R

    Hai,

    Earlier, I was having the problem to see the hidden folders, though I checked the radio button “Show all hidden folder & files” option. But after installing revmon killer, I got relief. Now I am facing a new problem that always a cursor of sand glass is sticking with the cursor arrow (point). How could I clear ? Also when I click the hard drive, I could open them instead a pop up window open with the heading of “script…” When I right click on the drive, I found “Auto play” command as the first command in the pane. How could I clear this problem. My pc becomes very slow. Please help to solve my problems

  6. Leandro

    Create this archive .vbs!!! And create job in Scheduled Task!!!

    ‘——————————————————————————–

    Set WshShell = WScript.CreateObject(“WScript.Shell”)

    Dim fso, d, dc
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set dc = fso.Drives
    For Each d in dc
    If d.DriveType = 2 Then
    Return = WshShell.Run(“defrag ” & d & ” -f”, 1, TRUE)
    End If
    Next

    Set WshShell = Nothing
    ‘——————————————————————————-

  7. Al Biheiri

    @Tie 1 On — add -v

    “I have made the Defrag batch file, but i’m not sure if it’s working properly. Is there any way of seeing the progress of the defrag?”

  8. Phil

    defrag c: -f
    defrag d: -f
    defrag f: -f

    does not work in a batch file

  9. Philip G Martin

    Correction. Does not work if you name your batch file “defrag.bat”

  10. francis mendoza

    try this

    @echo off
    c:\WINDOWS\system32\defrag c: /f
    c:\WINDOWS\system32\defrag d: /f
    c:\WINDOWS\system32\defrag e: /f
    pause

  11. francis mendoza

    open notepad then type

    @echo off
    c:\WINDOWS\system32\defrag c: /f
    c:\WINDOWS\system32\defrag d: /f
    c:\WINDOWS\system32\defrag e: /f
    pause

    then save the file in filename.bat extension
    then double click the file then you have
    your automatic defrag for all drive

    hope this will help you guys

  12. Robert Ryken

    How do I open a notpad e-mail

  13. shinchan

    defrag c:
    defrag d:
    defrag e:

    this didnt work for me, only the c drive was defragmented and the remaining drives were skipped i dont know why , can anybody tell me ?

  14. Navvie

    The Windows defrag program does a poor job to be honest. How many times have you seen the report at the end of a defrag and you still have fragmented files? Hmm, well thats a good defrag tool.

    MyDefrag (previously jkdefrag) does a much better job in my experience, not only defragging your disks but optimizing them so, for example, the files that Windows loads on boot up at together in order at the outside edge of the disk, which is the fastest possible place to put them.

    Your hard drive performs its slowest possible reading when it is loading small files at random locations across the disk. Think 0.5 MB/s and slower!

  15. B

    doesn’t work…
    it only opens the cmd window and the text runs endlessly but the command never executes

  16. IMTech

    defrag C: -f
    defrag D: -f
    defrag E: -f

    Ensure the drive letter is caps like this…

  17. Pacific

    francis mendoza is right. this works:

    c:\WINDOWS\system32\defrag c: /f /v
    c:\WINDOWS\system32\defrag f: /f /v
    c:\WINDOWS\system32\defrag g: /f /v

    add the /v switch (verbose) if you want to see the defrag progress & *.bat file can be run as scheduled task …

  18. Prosenjit Das

    When I boot up my PC and after 5 to 10 seconds after it reaches to the Desktop Screen, Internet Explorer Window automatically pops up…. I have tried to disable the Startup from MS Config and also tried to reset the Browser, but no help.I am using IE 8… Please help me with this issue…..

Enter Your Email Here to Get Access for Free:

Go check your email!