| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# show sorted content of 7z archive with date+time, size and file name |
| 4 |
# surpress superflous information and ignores password prompt |
| 5 |
|
| 6 |
$0 =~ s:.*/::; |
| 7 |
|
| 8 |
$usage = "usage: $0 file.7z\n"; |
| 9 |
die $usage if scalar(@ARGV) != 1 or "@ARGV" =~ /^-/; |
| 10 |
|
| 11 |
$file = shift @ARGV; |
| 12 |
|
| 13 |
die "$0: \"$file\" does not exist\n" unless -e $file; |
| 14 |
die "$0: \"$file\" is not a regular file\n" unless -f $file; |
| 15 |
die "$0: \"$file\" is not readable\n" unless -r $file; |
| 16 |
|
| 17 |
open $list,'-|',qw'7za l -px',$file or exit $?; |
| 18 |
|
| 19 |
# default table columns and lengths |
| 20 |
$r1s = 20; |
| 21 |
$r1l = 6; |
| 22 |
$r2s = 39; |
| 23 |
$r2l = 14; |
| 24 |
|
| 25 |
while (<$list>) { |
| 26 |
die "$1\n" if /(Error:.*)Wrong password/; |
| 27 |
if (/^( +Date.*)( Attr )( +Size )( +Compressed +)(Name)/) { |
| 28 |
$r1s = length($1); |
| 29 |
$r1l = length($2); |
| 30 |
$r2s = length($1)+length($2)+length($3); |
| 31 |
$r2l = length($4); |
| 32 |
&reduce; |
| 33 |
print; |
| 34 |
last; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
$_ = <$list>; |
| 39 |
&reduce; |
| 40 |
print; |
| 41 |
|
| 42 |
while (<$list>) { |
| 43 |
s:$:/: if substr($_,$r1s,1) eq 'D'; |
| 44 |
$file = substr($_,$r2s+$r2l,999); |
| 45 |
&reduce; |
| 46 |
if (/^---/) { |
| 47 |
$tail = $_; |
| 48 |
last; |
| 49 |
} |
| 50 |
$list{$file} = $_; |
| 51 |
} |
| 52 |
|
| 53 |
if (defined($_ = <$list>)) { |
| 54 |
&reduce; |
| 55 |
$tail .= $_; |
| 56 |
} |
| 57 |
|
| 58 |
foreach $file (sort keys %list) { |
| 59 |
print $list{$file}; |
| 60 |
} |
| 61 |
|
| 62 |
print $tail; |
| 63 |
|
| 64 |
sub reduce { |
| 65 |
substr($_,$r2s,$r2l) = ''; # delete Compressed column |
| 66 |
substr($_,$r1s,$r1l) = ''; # delete Attr column |
| 67 |
} |