Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Mar 2002
Posts: 30
Q
Junior Member
OP Offline
Junior Member
Q
Joined: Mar 2002
Posts: 30
Everyone who reads this forum either knows or should know that they need to degragment their hard drive regularly if they are using Windows.

For some of us, however, we have to defrag so infrequently that we often forget to do so at all.

One solution is to automate the task by creating a "Scheduled Task"[1] that runs at weekly or monthly intervals depending on your computer usage. This solution bores me.

The best solution would be to defrag only when the disk actually needs defragmenting. Perl to the rescue![3]

If you are running Windows XP, the Disk Defragmenter can be used to simply analyze the disk.[2] By using a small perl script to parse the analysis, we can create a Scheduled Task that will only Defragment our disk when a defined level of File Fragmentation is reached.[4]

The following perl script runs the Disk Defragmenter using the analysis only and verbose arguments (-a and -v, respectively). It then stores the reported percentage of file fragmentation in a variable and compares it to $frag_max. If the actual fragmentation is equal to or greater than $frag_max, the script then runs the Disk Defragmenter utility.

Code
use strict;
my @analysis = `defrag C: -a -v`;
if ($analysis[13] =~ /File fragmentation[^\w]*(\d\d*)/){
  my $frag = $1;
  my $frag_max = 10;
  system "defrag C:" if ($frag >= $frag_max);
}
NOTE: As many of you can probably see, this script relies on the standard output of the Disk Defragmenter utility. If this output were to change or is different for some reason, this script could break.

ALSO NOTE: You will need to change C: to whatever letter is assigned to the drive you want defragmented. And $frag_max can be changed to whatever percentage of file fragmenation you believe is appropriate.

You can store this script as defrag.pl in the directory of your choosing and create a Scheduled Task that will run it on a monthly, weekly, or even daily basis.

[1] Creating a Scheduled Task is easy as pie. In Windows XP Professional, the Scheduled Task utility is found in Start->Programs->Accessories->System Tools.
There is a Add Scheduled Task wizard that will help you create the Task very easily. (You will most likely need to browse for defrage.pl when prompted to select a program to run.)

[2] I only have Windows XP Professional available to me at the moment. If this does not work on Windows XP Home I will be both surprised and sorry.

[3] Perl is needed for this solution; however, similar scripts can be written in almost any language. If you do not have Perl installed on your system, I suggest downloading ActivePerl .
It is easy to install and fun to use.

[4] I have chosen to use the File fragmentation data rather than Total fragmentation or any of the other metrics that the analysis gives because I believe that File fragmentation is the most important factor in terms of fragmentation that affects performance.

Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
I use DiskKeeper Pro Premium (WinXP and 2k use the "freeware" version which comes bundled with windows).

It is schedualed to run every wednesday at 6am and to run on a continuous basis until noon. this is set on all machines.


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner

Link Copied to Clipboard
Member Spotlight
Phatal
Phatal
Houston, TX
Posts: 298
Joined: April 2004
Forum Statistics
Forums41
Topics33,840
Posts68,858
Average Daily Posts1
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Where and how do you torrent?
by danni75 - 03/01/24 05:58 AM
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
Cyrez 1
Girlie 1
unreal 1
Crime 1
Powered by UBB.threads™ PHP Forum Software 7.7.5