# !perl -sw use Tk; use strict; use Win32::Process; local $|=0; my $W = MainWindow->new; $W->title("Select Job"); $W->iconname('select job'); my $file_selected; # Read the directory contents - Put in a path were you have files placed # use a ARG of . to select from the current directory. my @dirContents = readDir ($ARGV[0]||"C:\\public"); my $TOP = $W->Toplevel; $TOP->title("data contents"); $TOP->geometry("+70+120"); $TOP->configure(-background => lc("aquamarine2")); my $tFrame = $TOP->Frame; my $bFrame = $TOP->Frame; $tFrame->configure(-background => lc("PaleTurquoise")); $bFrame->configure(-background => lc("PaleTurquoise")); # Create the label for editing the file my $lab = $tFrame->Label(-text => "Double click to edit file: ", -background => "PaleTurquoise", -anchor => 'e'); # Create a listbox with the contents of the directory. my $ent = $tFrame->Scrolled(qw/Listbox -setgrid 1 -height 16 -width 40 -scrollbars e -selectmode single/); for(@{dirContents}) { $ent->insert(0, "$_"); } $ent->bind( '', sub { my $pid; $file_selected = $ent->get('active'); print .$/; Win32::Process::Create( $pid, $ENV{COMSPEC}, "/c \"$file_selected\"", 0, 0, "." )|| die ErrorReport(); } ); # Quit the edit directory contents popup my $quitButton = $bFrame->Button(-text => "Quit", -width => 12, -background => "PaleTurquoise", -activebackground => "PaleTurquoise", -command => sub { $TOP->destroy; } # strictly not necessary ); # Instead of pack, using grid to place more precisely. Tk::grid($tFrame, -row => 0, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($bFrame, -row => 1, -column => 0, -sticky => 's', -padx => 10, -pady => 10, ); Tk::grid($quitButton, -row => 0, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($lab, -row => 1, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($ent, -row => 1, -column => 1, -sticky => 'w', -padx => 10, -pady => 10, ); MainLoop; sub readDir { my ($DirName) = @_; opendir (INDIR,$DirName) or die "\nCannot open $DirName: $!\n"; my @DirContents = grep{ !/^\.\.?$/ && -f $_ } map{ "$DirName\\$_" }readdir(INDIR); close (INDIR); return @DirContents; }