Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Re: Re: chdir does not work on win2000

by juo (Curate)
on May 28, 2001 at 20:32 UTC ( #83752=note: print w/replies, xml ) Need Help??

in reply to Re: Re: chdir does not work on win2000
in thread chdir does not work on win2000

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; }

Replies are listed 'Best First'.
Re: Re: Re: Re: chdir does not work on win2000
by the_slycer (Chaplain) on May 28, 2001 at 20:54 UTC
    The first time that I ran this, I received an error message when I hit the browse button, "ERROR in chdir: No such file or directory" .. this is because by default it looks like it is hitting "c:\\tmp" - I changed this to "c:\\temp", tried again, and did not receive the error. While browsing I can navigate to different folders etc no problem and see all of their contents. To me that sounds like it is working.
(tye)Re: chdir does not work on win2000
by tye (Sage) on May 28, 2001 at 21:09 UTC

    This isn't a problem with chdir, it appears to be a problem specific to directory named "tmp". If I try to chdir to a directory that doesn't exist, then the "Browse" button shows me files in the working directory of the script. If I successfully chdir, then it shows me files in that directory. But on both of those cases, if the directory name is "tmp", then I am instead shown files in the "My Documents" folder. Sounds like just the kind of thing Microsoft would do.

    An aside: If you cancel out of the Browse window, you get a two-button dialog box that either throws you back into the Browse window or exits the program. You really should allow the user to cancel the Browse window and return to the original form in case they change their mind about browsing.

            - tye (but my friends call me "Tye")

      Dear Tye, Are you using Win2000. With me it doesn't change the directory on Windows2000. When the browser open it shows me the directory last browsed too and not the directory that is returned by cwd(). The directory that is returned by cwd() is the directory were I started the script from. When I use chdir that directory has been changed but the directory in the browser stays untouched. When I browse to another location in the browser and I exit the browser that location is now stored and shown everytime I open the browser even when I reboot. It's that pointer I am not able to change. I believe it must be somewhere a setting in the windows2000 register that is not correct. On Windows NT it is working fine. Did anybody had simular problems ?

      my $_pwd = getcwd(); print "$_pwd\n"; # shows c:/perl/training : directory were I start + from. chdir("c:\\public") or print STDERR "\n\tERROR in chdir: $!\n"; $_pwd = getcwd(); print "$_pwd\n"; # shows c:/perl/public: directory have been chang +ed

        Yes, my experiments were done on Win2K.

        Here is the documentation of the "problem" (from the documentation for the OPENFILENAME structure that is passed to the GetOpenFileName function):

        lpstrInitialDir (a field in that structure)

        Pointer to a string that specifies the initial file directory.

        Windows NT 5.0 and later; Windows 98 and later:

        If lpstrInitalDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.

        If lpstrInitalDir is NULL and the current directory does not contain any files of the specified filter types, the initial directory is the personal files directory of the current user. To specify the current user's personal files directory as the initial directory, set lpstrInitialDir to the path returned by calling theSHGetSpecialFolderLocation function with the CSIDL_PERSONAL flag.

        Earlier versions of Windows and Windows NT:

        If lpstrInitalDir is NULL, the initial directory is the current directory.

        So I was close. The problem isn't with directories named "tmp", it is with directories that don't contain any files of the type you requested to be opened.

        The documentation implies that if you change this value to not be NULL, then things will work as you desire. Checking the source code for Tk (download Tk800_023_tar.gz from CPAN, extract files, find call to GetOpenFileName in Tk800.023\pTk\mTk\win\tkWinDialog.c, etc.) I see that specifying the -initialdir option should take care of that. Of course, you said that you already tried that. ):

        Perhaps you should experiment some more on exactly how you pass the -initialdir in. I know, for example, that file dialogues are one of the few places in Win32 that you can't type forward slash (/) as a directory separator. Perhaps the -initialdir also requires that only back slashes (\) be used?

                - tye (but my friends call me "Tye")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://83752]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-03-20 00:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.