Defragment Hard Drive using Batch file
Windows 11/10 runs automatic drive optimizations regularly by default. To defragment a single hard drive or multiple drives on your Windows PC using a Batch file, you first need to create the batch file and then run the .bat file with admin privilege. Here’s how:
Press Windows key + R to invoke the Run dialog.In the Run dialog box, type notepadHit Enter to open Notepad.Copy and paste the syntax below into the text editor.
In this example, we assume you want to defrag 4 drives. You need to edit the list to match the drives that you want to defragment using the batch file. If you want to defrag just one drive, then specify only the drive.
Save (preferably, to the desktop) the file with a name and append the .bat file extension – eg; DefragDrive.bat and on the Save as type box select All Files.Now, to defrag the drive(s), simply run the batch file with admin privilege (right-click the saved file and select Run as Administrator from the context menu).
Alternatively, instead of manually running the batch file, you can schedule the batch file to run automatically on your Windows 10/11 device. That’s it! Defragging your computer can both solve and prevent a number of problems. If you don’t regularly defrag your hard drive, your computer may run slowly and/or may take a long time to start up after you turn it on. If a hard drive is too fragmented, ie., File fragmentation is high, then your computer may freeze up or not start at all. While the default defragger is good enough for most of us, there are some who prefer to use Free Defragmentation Software. You may want to have a look at these too.