Dear sisters and brothers in PERL,

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 line

for (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!


Learning is like swimming against the current - as soon as you stop you'll drift back
(Chinese proverb)

In reply to Directory and file selection with PERL/Tk by chanklaus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.