Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

chdir does not work on win2000

by juo (Curate)
on May 28, 2001 at 19:11 UTC ( [id://83733]=perlquestion: print w/replies, xml ) Need Help??

juo has asked for the wisdom of the Perl Monks concerning the following question:

<text> Perl Version 5. When I use the chdir function on windows2000 it does not seem to work. I also tried the parameter -initialdir and it also does not work. When I use it on Winnt it works without any problem. Any clues ? <text> <code> my $_pwd = getcwd(); chdir("c:\\tmp") or print STDERR "\n\tERROR in chdir: $!\n"; $file = $w->getOpenFile(-filetypes => \@types); <code>

Replies are listed 'Best First'.
Re: chdir does not work on win2000
by the_slycer (Chaplain) on May 28, 2001 at 19:16 UTC
    Works fine for me - v5.60 (ActiveState build).
    chdir ("c:/temp"); exec "dir";
    Prints out my temp dir. What kind of problem are you having? What is the error you get back? "Doesn't work" doesn't tell me a lot.
      It works with that function but not in combination with the native windows 2000 browser : getOpenFile Regards, Pieter

        Here comes a standalone sample of the windows 2000 native browser. You will need the Tk module. You will notice the chdir in their and it doesn't produce any error but it also does not change the directory. It always goes back to the last directory browsed too. says Simply use your question

        #!/perl/bin/perl -w # always with warnings on.. use Tk 800.000; use strict; use vars qw/$edaType/; use FileHandle; my $edaType = "Visula"; use Cwd; cadFileSelect(); sub cadFileSelect { my $edaType = shift; my $cadFile = shift; my $TOP = MainWindow->new; $TOP->title("Select a file"); $TOP->geometry("+50+100"); $TOP->configure(-background => lc("aquamarine2")); my $tFrame = $TOP->Frame; my $bFrame = $TOP->Frame; $tFrame->configure(-background => lc("PaleTurquoise")); $bFrame->configure(-background => lc("PaleTurquoise")); my $lab = $tFrame->Label(-text => "Select a file to open: ", -background => "PaleTurquoise", -anchor => 'e'); my $ent = $tFrame->Entry(-width => 50, -textvariable => \$$cadFile, -background => "PaleTurquoise",); my $but = $tFrame->Button(-text => "Browse ...", -background => "PaleTurquoise", -activebackground => "PaleTurquoise", -command => sub { $$cadFile = fileDialog($edaType,$TOP); }); my $quitButton = $bFrame->Button(-text => "Quit", -width => 12, -background => "PaleTurquoise", -activebackground => "PaleTurquoise", -command => sub { $TOP->destroy; # strictly not necessary Tk::exit; }); my $continueButton = $bFrame->Button(-text => "Continue", -width => 12, -background => "PaleTurquoise", -activebackground => "PaleTurquoise", -command => sub { if($$cadFile) { $TOP->destroy; } else { my $ch = $TOP->messageBox('-icon' => 'info', -type => 'OK', -title => 'Information', -message => "Please select $edaTyp +e input file"); } }); 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($continueButton, -row => 0, -column => 1, -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, ); Tk::grid($but, -row => 1, -column => 2, -sticky => 'w', -padx => 10, -pady => 10, ); MainLoop; } sub fileDialog { # # note now receiving more args... # my ($textWidget, $w, $mainWin) = @_; my @types = setFileTypes($edaType); my $file = undef; # Loop until valid selection is made, or user hits "Cancel" while(not defined($file)) { my $_pwd = getcwd(); chdir("c:\\tmp") or print STDERR "\n\tERROR in chdir: $!\n"; $file = $w->getOpenFile(-filetypes => \@types); if(defined($file) && $file ne '') { return $file; chdir($_pwd); #back to orig dir } else { my $ch = $w->messageBox('-icon' => 'error', -type => 'OKCancel', -title => 'Message', -message => "Please select a $edaType input file") +; if($ch eq "cancel") { $w->destroy; chdir($_pwd); #back to orig dir return $ch; } } } return $file; } sub setFileTypes { my $edaType = shift; return (["Visula Cadif file", '*'], ["Visula Cadif file", 'cadif.file'] ) if($edaType eq "Visula"); # ..........etc. # ...and in case something is very wrong, and edatype doesn't match... return undef; }
Re: chdir does not work on win2000
by Beatnik (Parson) on May 28, 2001 at 19:21 UTC
    Check the latest perl version, IIRC there were some Win2K issues fixed in newer releases (since Win2K didn't exist back with perl 5.005)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: chdir does not work on win2000
by TheoPetersen (Priest) on May 28, 2001 at 19:22 UTC
    It worked fine for me, after I created C:\tmp. Are you sure it exists?

    My Perl is 5.6.1, and Cwd.pm is 2.03. What's yours?

    Also, post whole scripts where possible, reduced to the part that produces the problem, and use <code> tags.

      My perl version is 5.005 and my Cwd.pm is version 2.01. Are you sure it is working in combination with the Tk function getOpenFile. Regards, Pieter

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://83733]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found