Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found