Defrag all Hard drives at once in Windows - gHacks Tech News

Defrag all Hard drives at once in Windows

The defragmentation tool that ships with Windows is pretty basic and does not offer features that you may need to make use of. I'm not talking about functionality in regards to defragmenting the hard drive to speed up operations, but about basic functionality that you may need. One example is that there is no option to defrag multiple partitions or drive at once. If you want to defragment multiple drives, you need to select the option after the defragmention of a drive completes. That's not that great of an option considering that you need to be present to run those commands and that you can't just keep the defrag running during night or at times when the computer is idle.

There is however an option that you have that you can make use of to defragment all of your partitions and drives at once. You can use a little batch file to do that which allows you to run it whenever you need to and it takes care of all drives you add to the batch file.

There are a couple of things you need to know though. You need to run the script with elevated rights which you can do easily by right-clicking on it and selecting to run the file as administrator. Just make sure you do so and everything else should be automatic from that moment on.

I have four partitions with the drive letters C:, D:, E: and F: which means that the batch script will look like the following:

@echo off
defrag.exe c: -f
defrag.exe d: -f
defrag.exe e: -f
defrag.exe f: -f

To create the batch file do the following. Create a plain text document and copy and paste the commands you see above to it. You may need to modify the drive letters and maybe even add or remove lines so that all of your drives are covered. Change the file extension to bat afterwards and make sure you do not have a .txt extension anymore.

  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:


    1. sspace said on July 8, 2007 at 2:38 am

      In Vista you can defrag all volumes with the command:
      “defrag -c” from an administrator command prompt .

    2. khu said on July 8, 2007 at 1:16 pm

      Or you can just use ScanDefrag:

    3. Captain Picard said on July 8, 2007 at 2:56 pm

      This is a good tip; not many people know that you can defrag multiple drives in windows. But even so, the windows defraggers take way too much time to defrag, and often they dont do a good job. (eg. they dont defrag the $MFT AFAIK). The Vista defragger also seems to be crippled wrt available options and progress display.

      If you go out of the freeware arena, there are some good defraggers like Diskeeper Pro that make defragging easy and fast. DK gives better options for defragging single or multiple drives, and the defrags are also much faster compared to windows. But Diskeeper’s trump card is the autodefrag mode…set it and forget about manually defragging from that point on. Might sound like hype, but actually works really well.

    4. gnome said on July 8, 2007 at 4:56 pm

      Yp, scandefrag it is then! Nice one Khu

    5. mosey said on July 11, 2007 at 3:17 am

      Sorry, newbie here – the line above goes into something called ‘batchfile.exe’ or something?

      Thanks :D

    6. Martin said on July 11, 2007 at 9:18 am

      mosey just create a file called defrag.bat and double-click it to execute.

    7. mosey said on July 12, 2007 at 10:03 am

      Martin: Thanks! :D I’ll give it a go!

    Leave a Reply