Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Don't ask to ask, just ask
 
PerlMonks  

win32/winxp, -r and chdir succeed but opendir fails, permission denied

by Anonymous Monk
on Feb 18, 2012 at 19:57 UTC ( #954794=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

On win32/winxp, -r and chdir succeed but opendir fails , permission denied

commands

echo %cd% perl -le " print -r 'Administrator' " perl -le " chdir 'Administrator' or die $! " perl -le " chdir 'Administrator' or die $!; opendir DIR, '.' or die $! + " perl -le " chdir 'Administrator' or die $!; opendir DIR, '.' or die $! +,$/,$^E " perl -e " die $] "

output

$ echo %cd% C:\Documents and Settings $ perl -le " print -r 'Administrator' " 1 $ perl -le " chdir 'Administrator' or die $! " $ perl -le " chdir 'Administrator' or die $!; opendir DIR, '.' or die +$! " Invalid argument at -e line 1. $ perl -le " chdir 'Administrator' or die $!; opendir DIR, '.' or die +$!,$/,$^E " Invalid argument Access is denied at -e line 1. $ perl -e " die $] " 5.014001 at -e line 1.

Is it bug?

Comment on win32/winxp, -r and chdir succeed but opendir fails, permission denied
Select or Download Code
Re: win32/winxp, -r and chdir succeed but opendir fails, permission denied
by LonelyPilgrim (Sexton) on Feb 18, 2012 at 20:13 UTC

    Seems like it might be more effective to run an actual script to step through the process and diagnose where this is breaking down:

    use strict; use warnings 'all'; use Cwd; my $docs = 'C:\Documents and Settings'; chdir($docs) || die "Couldn't change directory to $docs: $!"; print "Current directory is ", getcwd, "\n"; if (-r 'Administrator') { print "Administrator is readable.\n"; } else { die "Couldn't read 'Administrator': $!"; } if (chdir('Administrator')) { print "Changed directory to Administrator.\n"; } else { die "Couldn't change directory to 'Administrator': $!"; } print "Current directory is ", getcwd, "\n"; if (opendir(ADMINDIR, "$docs\\Administrator")) { print "Opened directory Administrator.\n"; } else { die "Couldn't open directory 'Administrator': $!"; }

    By the way, be sure you're not trying to opendir on your directory after you've chdir'ed into it. I caught that mistake in whipping up the above. To opendir on your current working directory, you either have to opendir(DIR, '.') or provide the full path.

      To opendir on your current working directory, you either have to opendir(DIR, '.') or provide the full path.
      Quoting the OP:
      opendir DIR, '.' or die $!
      which he does right after a successful chdir. Which point are you trying to make here?

        I noted my own mistake. And then noticed that the OP had not made it. I was not implying any incompetence on his part, but acknowledging my own. I didn't remove the comment because I hoped that it might be helpful to someone else.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-04-17 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (454 votes), past polls