chanklaus has asked for the wisdom of the Perl Monks concerning the following question:
for my applications I am looking for both a pure directory selection and a mixed fie and directory selection in PERL/Tk. There are a number of example programs available in the net, and I tried some of them, but I didn't find any which does exactly what I want to have. So I would like to ask you for help to find such an example program.
One of the examples for a directory selection tree I found and which I like is from Slaven Resic, located at http://www.perltk.org/files/dirtree.pl.txt:
use Tk; use Tk::DirTree; use Cwd; my $top = new MainWindow; $top->withdraw; my $t = $top->Toplevel; $t->title("Choose directory:"); my $ok = 0; my $f = $t->Frame->pack(-fill => "x", -side => "bottom"); my $curr_dir = 'd:'; #my $curr_dir = Cwd::cwd(); my $d; $d = $t->Scrolled('DirTree', -scrollbars => 'osoe', -width => 35, -height => 20, -selectmode => 'browse', -exportselection =>1, -browsecmd => sub { $curr_dir = shift }, -command => sub { $ok = 1; }, )->pack(-fill => "both", -expand => 1); $d->chdir($curr_dir); $f->Button(-text => 'Ok', -command => sub { $ok = 1 })->pack(-side => 'left'); $f->Button(-text => 'Cancel', -command => sub { $ok = 1 })->pack(-side => 'left'); $f->waitVariable(\$ok); if ($ok == 1) { warn "The resulting directory is '$curr_dir'\n"; } __END__
It does more or less what I want it to do, only that it displays the directory tree of one drive only, and I want to have a directory tree displaying all of the drives which are in use, both hard discs and rather temporary device like USB sticks. In an ideal situation the directory tree starts with a display of all drives (c:, d:, etc.) with the highest level of directorys, from which people then can click down to the folder they want to select.
With a slight modification of the above mentioned example program I almost get that: if I replace the line$d->chdir($curr_dir);
through
$d->chdir("c:"); $d->chdir("d:"); $d->chdir("e:");
I'll have all of the trees available, albeit the drive from which the program is started doesn't look exactly the way I described above, but opens to the directory in which the program is located.
I could live with this situation, but a more dynamic display through a program linefor (my $i=0;$i<=$#drives;++$i) { $d->chdir($drives[$i); }
(in which the @drives list contains all active drives, eg. estimated through an analysing function) didn't work, and I couldn't find the reason why.
So, once again, my questions:Where can I find any example program which creates me a file and directory selection tool which is able to display the entire directory structure of a computer instead of just the structure for one drive only?
and/or
How can I modify the above mentioned program to show this entire drive and directory structure (built from a drive list) without hard coding the drives available on the computer?
Many thanks for your help,
best greetings and wishes,
Yours
chanklaus!
Amen!
(Chinese proverb)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Directory and file selection with PERL/Tk
by biohisham (Priest) on Sep 25, 2009 at 10:34 UTC | |
Re: Directory and file selection with PERL/Tk
by BioLion (Curate) on Sep 25, 2009 at 10:30 UTC | |
Re: Directory and file selection with PERL/Tk
by Marshall (Canon) on Sep 26, 2009 at 22:52 UTC | |
by elef (Friar) on Mar 20, 2012 at 09:22 UTC | |
by jeri_rl (Initiate) on Jun 11, 2013 at 19:15 UTC | |
by elef (Friar) on Jun 13, 2013 at 12:02 UTC | |
Re: Directory and file selection with PERL/Tk
by lamprecht (Friar) on Sep 25, 2009 at 11:02 UTC | |
Re: Directory and file selection with PERL/Tk
by planetscape (Chancellor) on Sep 26, 2009 at 08:55 UTC |