rendered paste body#! /usr/bin/perl
#
#use warnings;use strict;
use Tk;
#
my $mw = MainWindow->new;
my $rep = $rep_base = '/home/francois';
opendir R_DIR,$rep or die "E/S : $!\n";
my (@rep,@sous_rep,@fic);
my ($lst_f,$lst_r,$elem, $dossier,$nr);
sub list_dir{
while (my $fic = readdir(R_DIR)){
# next iF $FIc =~ /^\./; # saute les fichiers qui commencent avec .
# next if -d "$rep/$fic";# saute les rpertoires
# if ( -d "$rep/$fic"){
push @rep,$fic;
# }
# else {
# push @fic,$fic;
# }
}
unshift @rep,".";
}
sub list_select{
my @select = $lst_f->curselection();
$elem = $lst_f->get($select[0]);
}
sub rep_list{
my @select = $lst_r->curselection();
$dossier = $lst_r->get($select[0]);
opendir R_LIRE, "$rep/$dossier"
or die "E/S : $!\n";
# $rep = "$rep_base/$dossier";
$rep="$rep/".$lst_r->get($select[0]);
while (my $k = readdir(R_LIRE)){
# next if $k =~ /^\./;
# next if -d "$rep/$dossier/$k";
push @rep,$k;
}
if ($dossier !~ /^\./){
$dossier = $rep . '/' . $dossier;
}
else { $dossier = $rep;}
$lst_r->delete(0,'end');
$lst_r->insert('end',sort tri @rep);
$nr ="Il y a ${\ (@rep + 0) } fichiers dans $dossier";
@rep=();
}
$mw -> title("Lister un rpertoire");
$mw->geometry("700x400+60+30");
$mw->maxsize(650,600);
$lst_r = $mw->Scrolled("Listbox",-scrollbars=>'e',
-background => 'white',)->place( -x => 0,
-y => 30,
-width => 300,
-height => 300,);
$lst_f = $mw->Scrolled("Listbox",-scrollbars=>'e',
-background => 'white',)->place( -x => 350,
-y => 30,
-width => 300,
-height => 300,);
opendir R_DIR,$rep or die "E/S : $!\n";
#list_dir();
$lst_r->insert('end',sort tri @rep);
$mw->Button( -text => '>>', -command => sub {my @select = $lst_r->curselection(); my $dir = $lst_r->get($select[0]); push @sous_rep, "$rep/$dir"; $lst_f->delete(0,'end'); $lst_f->insert('end',sort tri @sous_rep); $lst_r->insert('end',sort tri @rep) },)->place( -x => 305, -y => 150, -width => 40, -height => 25);
$mw->Button( -text => '<<', -command => sub {$mw->destroy()},)->place( -x => 305, -y => 180, -width => 40, -height => 25);
$lst_f->bind("<Button-1>",\&list_select);
$lst_r->bind("<Button-1>",\&rep_list);
$mw->Label( -textvariable => \$dossier,
-foreground => 'purple',)->place( -x => 350, -y => 0,);
$mw->Label( -textvariable => \$elem,
-foreground => 'blue')->place( -x => 280, -y => 370,);
while (my $fic = readdir(R_DIR)){
# next iF $FIc =~ /^\./; # saute les fichiers qui commencent avec .
# next if -d "$rep/$fic";# saute les rpertoires
# if ( -d "$rep/$fic"){
if(-d "$rep/$fic"){
push @rep,$fic."/";
}else{
push @rep,$fic;
}
# }
# else {
# push @fic,$fic;
# }
}
unshift @rep,".";
# trier sans tenir compte de la casse
# un sort simple comme dans le 1er message
# c'est un tri asciibetique (les chiffres,les majuscule ensuite les minuscules)
# la fonction tri permet le tri alphabetique
#
sub tri { lc($a) cmp lc($b) };
$lst_f->insert('end',sort tri @fic);
$lst_r->insert('end',sort tri @rep);
$mw->Label( -textvariable => \$nr,
-foreground => 'brown',)->place( -x => 180 , -y => 350,);
$mw->Label( -text => "$rep contient ${\(@rep-1)} rpertoires.",)->place( -x => 0, -y => 0,);
$mw->Button( -text => 'Quitter', -command => sub {$mw->destroy()},)->place( -x => 550, -y => 350,);
MainLoop;