Skip to content

Instantly share code, notes, and snippets.

@kimmel
Created July 7, 2012 06:54
Show Gist options
  • Save kimmel/3065174 to your computer and use it in GitHub Desktop.
Save kimmel/3065174 to your computer and use it in GitHub Desktop.
dir processing script
#!/usr/bin/perl
use utf8;
use v5.10;
use warnings;
use File::Spec;
if ( $#ARGV == -1 ) {
say 'Usage: fix_dirs.pl [FILE]';
exit;
}
my %dirs = ();
while ( my $line = <> ) {
my ( $pf, $fsize ) = split /[ ]{2}/ms, $line;
chomp $fsize;
my ( undef, $d, $f ) = File::Spec->splitpath($pf);
my $prefix = '/';
my $key = '';
foreach my $piece ( split /\//xms, $d ) {
next if ( $piece eq q() );
my $entry = "D $prefix$piece 1K 1341691250";
$prefix = "$prefix$piece/";
$key = $entry;
next if ( exists $dirs{$entry} );
$dirs{$entry} = '';
}
$dirs{$key} .= "F $f $fsize 1341691250\n";
}
print <<'HEADER'
[kdirstat 2.5.3 cache file]
# Do not edit!
#
# Type path size mtime <optional fields>
HEADER
;
foreach ( sort keys %dirs ) {
say $_;
say $dirs{$_};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment