Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi,

I am still persuing a solution to what should be a trivial problem:

How to get a list of the immediate subdirs of a user-supplied path:

I have a solution (thanks to the help of the wanderers of these noble halls) that works for the supplied path of "." but NOT for a supplied relative or absolute path UNLESS that is the cwd!?

Is this a code (dumb user) error? A platform (dumb os) specific error? Or -- horror of horrors -- the result of a Perl library writers off-day?

The following code is used to demonstrate the problem:

C:\www\NB.biz\html>type test.pl #!e:/perl/bin/perl.exe -w use strict; use diagnostics; print "Arg:", $ARGV[0], "\n"; $, = "\n"; opendir(DIR, $ARGV[0] ) or die ".: $!"; print "\nReaddir:\n", readdir(DIR); rewinddir(DIR); print "\nOnly directories:\n", grep {-d } readdir(DIR); rewinddir(DIR); print "\nJust named directories:\n", grep { -d $_ and $_ ne '.' and $ +_ ne '..'} read dir(DIR); closedir(DIR);

I pushed the long demonstration of the code failing here:

C:\www\NB.biz\html>test.pl . Arg:. Readdir: . .. blank.htm css Document graphics index.htm logo.htm Menu.pl NB.biz.tws Products test.pl Only directories: . .. css graphics Products Just named directories: css graphics Products C:\www\NB.biz\html>cd .. C:\www\NB.biz>html\test.pl html Arg:html Readdir: . .. blank.htm css Document graphics index.htm logo.htm Menu.pl NB.biz.tws Products test.pl Only directories: . .. Just named directories: C:\www\NB.biz>html\test.pl html\ Arg:html\ Readdir: . .. blank.htm css Document graphics index.htm logo.htm Menu.pl NB.biz.tws Products test.pl Only directories: . .. Just named directories: C:\www\NB.biz>html\test.pl html\. Arg:html\. Readdir: . .. blank.htm css Document graphics index.htm logo.htm Menu.pl NB.biz.tws Products test.pl Only directories: . .. Just named directories: C:\www\NB.biz>html\test.pl \www\NB.biz\html Arg:\www\NB.biz\html Readdir: . .. blank.htm css Document graphics index.htm logo.htm Menu.pl NB.biz.tws Products test.pl Only directories: . .. Just named directories: C:\www\NB.biz>html\test.pl \www\NB.biz\html\ Arg:\www\NB.biz\html\ Readdir: . .. blank.htm css Document graphics index.htm logo.htm Menu.pl NB.biz.tws Products test.pl Only directories: . .. Just named directories: C:\www\NB.biz>

In reply to -d fails outside the current working directory by Anonymous Monk

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 contemplating the Monastery: (4)
As of 2024-04-25 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found