| 1 |
#!/usr/local/bin/perl -w |
| 2 |
|
| 3 |
use Tk; |
| 4 |
use Tk::Table; |
| 5 |
|
| 6 |
my $now = time; |
| 7 |
|
| 8 |
my $mw = MainWindow->new; |
| 9 |
|
| 10 |
my $t = $mw->Table(-scrollbars => 'e',-fixedrows => 1, -rows => 20); |
| 11 |
$t->pack(-expand=> 1, -fill => 'both'); |
| 12 |
|
| 13 |
$dir = (@ARGV) ? shift : '.'; |
| 14 |
opendir(DIR,$dir) || die "Cannot opendir $dir:$!"; |
| 15 |
my $r = 1; |
| 16 |
my $c = 0; |
| 17 |
my $name; |
| 18 |
foreach $name ([-text => "Mode",-anchor => 'e'], |
| 19 |
[-text => "Ln",-anchor => 'e'], |
| 20 |
[-text => "User",-anchor => 'w'], |
| 21 |
[-text => "Size",-anchor => 'e'], |
| 22 |
[-text => "Date",-anchor => 'w'], |
| 23 |
[-text => "Name",-anchor => 'w']) |
| 24 |
{ |
| 25 |
$t->put(0,$c++,$t->Label(@$name,-relief => 'raised')); |
| 26 |
} |
| 27 |
$t->configure(-columns => $c) if ($c > $t->cget('-columns')); |
| 28 |
|
| 29 |
my @opt = (-relief => 'groove'); |
| 30 |
|
| 31 |
foreach $name (sort readdir(DIR)) |
| 32 |
{ |
| 33 |
my $c = 0; |
| 34 |
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
| 35 |
$blksize,$blocks) = lstat("$dir/$name"); |
| 36 |
die "Cannot lstat $dir/$name:$!" unless (defined $dev); |
| 37 |
$t->put($r,$c++,$t->Label(@opt,-text => sprintf("%o",$mode),-anchor => 'e')); |
| 38 |
$t->put($r,$c++,$t->Label(@opt,-text => $nlink,-anchor => 'e')); |
| 39 |
$t->put($r,$c++,$t->Label(@opt,-text => $uid,-anchor => 'w')); |
| 40 |
$t->put($r,$c++,$t->Label(@opt,-text => $size,-anchor => 'e')); |
| 41 |
$t->put($r,$c++,$t->Label(@opt,-text => fmtdate($mtime),-anchor => 'w')); |
| 42 |
$t->put($r,$c++,$t->Label(@opt,-text => $name,-anchor => 'w')); |
| 43 |
$r++; |
| 44 |
} |
| 45 |
closedir(DIR); |
| 46 |
$t->update; |
| 47 |
$t->focus; |
| 48 |
MainLoop; |
| 49 |
|
| 50 |
sub fmtdate |
| 51 |
{ |
| 52 |
my $t = shift; |
| 53 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t); |
| 54 |
my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
| 55 |
sprintf("%s %2d %2d:%2d", $mon[$mon], $mday,$hour,$min); |
| 56 |
} |