Advertisement
mikelieman

bin/image-db-analysis-02.pl

Dec 7th, 2014
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.82 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # sort by directory size
  4.  
  5. use v5.12;
  6. use warnings;
  7. use File::Basename;
  8. use Text::CSV;
  9.  
  10. my $csv = Text::CSV->new( { binary => 1 } )
  11.   or die "Cannot use CSV: " . Text::CSV->error_diag();
  12.  
  13. $csv->column_names(qw( fullpath filename mtime size digest ));
  14.  
  15. my $database = "fileinfo.db";
  16.  
  17. open my $FH, q{<:encoding(utf8)}, $database or die "$database: $!";
  18.  
  19. say "connected to database '$database' successfully";
  20.  
  21. my %dir_info;
  22.  
  23. while ( my $hr = $csv->getline_hr($FH) ) {
  24.     $dir_info{ dirname( $hr->{fullpath} ) }->{SIZE} += $hr->{size};
  25.     $dir_info{ dirname( $hr->{fullpath} ) }->{COUNT}++;
  26. }
  27.  
  28. foreach
  29.   my $tmp_dir ( sort { $dir_info{$b}->{SIZE} <=> $dir_info{$a}->{SIZE} }
  30.     keys %dir_info )
  31. {
  32.     say " $dir_info{$tmp_dir}->{SIZE} $tmp_dir ( $dir_info{$tmp_dir}->{COUNT})";
  33. }
  34.  
  35. __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement