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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
There are a number of ways to do this, although I cannot say definitely if this will work with a space in a directory. However it should, theoretically still work by doing any of the following:

#!/usr/bin/perl -w use strict; my @result = map { glob($_) } "*"; foreach (@result) { if (-d "$_") { print "$_ is a directory\n"; } }

This is directly from the camel book and will return a listing of everything in the current directory. See the camel book for more details on glob.

You can also use opendir and readdir to get a handle, open the directory, read the directory, test if any files in directory are directories. You might want to take the advice from the camel book on this and use grep to avoid the "." and ".." directories, but it sounds like you are on a non-*nix system so you may not need to worry about it.

The other way, is to use the File::Find which is well documented both here and at CPAN.

Hope that helps. Nice to know you have so many choices, huh? Ain't Perl great!


I admit it, I am Paco.

In reply to Re: Opening a Directory by jonjacobmoon
in thread Opening a 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? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-12-03 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?