note
thundergnat
<p>(Written before you showed your code) Probably the reason is that readdir just returns the file name. If you want to do file tests on the file, you need to include the path... like so:</p>
<c>
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my %tk;
$tk{mw} = MainWindow->new;
$tk{frame} = $tk{mw}->Frame->pack(
-expand => 1,
-fill => 'both',
-anchor => 'nw'
);
$tk{listbox} = $tk{frame}->Scrolled(
'Listbox',
-selectmode => 'single',
-scrollbars => 'ose',
)->pack(
-expand => 1,
-fill => 'both',
-padx => 5,
-pady => 5,
);
my $dir = q|/|;
readDir($dir);
MainLoop;
sub readDir{
my $dir = shift;
opendir(my $dh, $dir) or die "Can't opendir $dir: $!";
my @all = readdir($dh);
for my $x (sort (@all)){
next if($x =~ /^\.$/);
$tk{listbox}->insert('end', $x);
if(-d $dir.$x){
print "$x\n";
$tk{listbox}->itemconfigure($tk{listbox}->size()-1, -foreground=>"#F00");
}
}
close $dh;
}</c>
1022963
1022963