Keeping your disks nicely defragmented is one of those things that keeps your machine running nice and smooth.
Defragmenting your Windows machine however is something you don’t really think of doing until someday you start looking for that rattlesnake hiding behind the computer to later realise it’s your hard drive that’s making all the ruckus.
To keep this from happening you can script and schedule the defrag to happen automatically when you are away from the computer. While defragging your computer there’s a serious chance it will become frustratingly slow so it’s probably really bad for your health to keep working on it in the same time.
So to make life easier I wrote this little batch script that you can download free of charge for your own use.
I called it defragall.bat
, and the only thing you have to do to make it work is tell it which drives it needs to sort out for you. To tell it which drives it needs to defrag you have to simply create a binary file (with a hex editor for example) containing the binary value of the drive you want defragged with A being 0001. So C becomes 0011 and D becomes 0100.
Quite simple isn’t it?
What? Not userfriendly you say? Well, I guess you’re right, so instead you can pass the drives you want defragged on to the script using the command line (very l33t innit?). For instance like this:
defragall.bat c d e
That’s more like it isn’t it?
Now to schedule this thing you only need drag the script into the Windows Scheduler (see the Control panel) and edit the startup parameters so you pass the right drive letters on to it. Once in there you can adjust the settings to your liking. For instance you can set it to start only when your computer has been inactive for 15 minutes around times that you’re usually away from your PC. I use this one at work to defrag over noon for instance. At home I have it retry for 4 hours (360 minutes) for when I’m working on the PC, so it’s bound to run at some point. For more help on scheduling tasks in Windows you can check out this Lifehacker post.
You can get the script here, licensed under the GPL. Props where props are due however. The idea came from yet another Lifehacker post, which has a more elaborate take on this script, but I found that the checkdisk in their version locked the script up sometimes, or causes unwanted checkdisks at boot, which I do not like.
Automated, painless, command line based defragging at your disposal for Windows XP and 2000 (might work on other versions as well).
Let me know if you dig it.
2 replies on “defragging the easy way”
Sounds like it wouldn’t be a dumb idea to grab those VIP files off that HDD and into a backup as well if you ask me. Defragging will probably take a shitload of time if it’s been ages since that happened, but if it’s rattling dangerously metalic… take backups, and pray for the best.
Rattlesnake behind the computer, well i thought all the noises were coming from an indigestion of my HDD. After all how much can the poor thing take:d i have brutally dumped and deleted stuff off it for ages wihouit checking fragmentation levels. And nw its like a bloated potato making whirring sounds every now and then. Maybe its last days! No point in putting off these maintenance chores, they only accelerate drive failures and crashes.