1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #!/usr/bin/perl
use warnings;
use strict;
use Tk;
# 1er Menu avec Scan répertoire
my $rep = 'w:\Public\script';
opendir R_DIR, $rep or die "E/S : $!\n";
my @rep;
my ( $lst, $elem );
my $mw = MainWindow->new;
$mw->title("Lister un répertoire");
$mw->Label(
-text => "\Ufichiers dans \E: $rep",
-relief => 'ridge',
)->pack();
$lst = $mw->Scrolled(
"Listbox",
-scrollbars => 'e',
-background => 'white',
)->pack(
-anchor => 'center',
-ipadx => '100',
-ipady => '100',
);
$lst->bind( "<Button-1>", \&list_select );
$mw->Label(
-textvariable => \$elem,
-foreground => 'blue'
)->pack();
while ( my $fic = readdir(R_DIR) ) {
next if $fic =~ /^\./; # saute les fichiers qui commencent avec .
next if -d "$rep/$fic"; # saute les répertoires
push @rep, $fic;
}
$lst->insert( 'end', sort tri @rep );
$mw->Label( -text => "Il y a ${ \(@rep+0) } fichiers.", )->pack();
my $entete2 = $mw->Label( -text => 'liste2' );
my $lst2 = $mw->Scrolled( 'Listbox', -scrollbars => 'osoe', );
$lst2->insert( 'end', qw/perl tk qt wx gtk2/ );
#Insertion 2nd Menu deroulant
my $liste = $mw->Listbox()->pack();
#Bouton envoyer
$mw->Button(
-text => '>>',
-command => sub {
my @elt_selectionnes = $lst->curselection();
foreach my $elt1 (@elt_selectionnes) {
$liste->insert( 'end', $lst->get($elt1) );
}
},
)->pack();
$mw->Button(
-text => 'Renommage Fichiers',
-command => sub {
#C'est ici que je voudrais donc renommer les fichiers presents dans la listbox
# rename ($elt1, "lot");
},
)->pack();
MainLoop;
sub tri { lc($a) cmp lc($b) }
sub list_select {
my @select = $lst->curselection();
$elem = $lst->get( $select[0] );
} |
Partager