Skip to content

Instantly share code, notes, and snippets.

@sebkirche
Created January 4, 2015 14:58
Show Gist options
  • Save sebkirche/f55ca9ed3fc0a5a62082 to your computer and use it in GitHub Desktop.
Save sebkirche/f55ca9ed3fc0a5a62082 to your computer and use it in GitHub Desktop.
defragment files not processed by system defrag tool (as listed in the final log) with SysInternals contig tool
# Process the XP defrag log file
# to defragment the "Files that cannot be defragmented" with SysInternals / defrag tool.
#
# Seki - 2014
use strict;
use warnings;
use Data::Dumper;
#~ use 5.10.1; #not compatible with my old 5.8.8, but I just need "say"
use constant DEBUG => 0;
use constant DEFAULT_FILE => 'VolumeC.txt';
my $cmd = '\tools\sys_net_tools\SysinternalsSuite\Contig.exe';
#define a local say
sub say { print ((join '', @_) . "\n"); }
my $filename = $ARGV[0] || DEFAULT_FILE;
my $cnt = 0;
my @processed;
my @unprocessed;
my $res;
say "Processing `$filename` (you can give another file name in the command line)";
open(FILE, "<:encoding(utf16)", $filename) or die "cannot open $filename : $!";
$/ = "\r\n";
while(<FILE>){
if (/-+/ ... eof(FILE)){ #we only care about the second part of the file
my $line = $_;
chomp($line);
say $line if DEBUG;
if ($line =~ /(\\.+)$/){
if (-f $1){
say "Processing `$1`...";
push @processed, $1;
$res = `$cmd "$1"`;
say $res if DEBUG;
} else {
push @unprocessed, $1;
}
}
}
}
close FILE;
say "Done.";
say "processed :\n" .
"---------\n" . join "\n", @processed;
say "not processed :\n" .
"-------------\n" . join "\n", @unprocessed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment