Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( [id://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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    Domain Nodelet?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2024-07-12 18:39 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.