SPUG: getting a list of directories

Tim Maher/CONSULTIX tim at consultix-inc.com
Thu Jan 20 15:31:15 CST 2000


On Thu, Jan 20, 2000 at 11:53:39AM -0800, Todd Wells wrote:
> I'd like to get a list of directory names (and only directory names) in
> /usr/myapp.  What's the best way to go about this?  I wish the cookbook had
> a recipe for this.  I see that readdir specifically excludes directory
> names.

Sheesh!  Such complicated solutions in previous replies!

If you don't need to descend into subdirectories, all you
need is this:

@dirs=grep { -d } <*> ;	# filter list, passing only directories

If you want hidden directories too, excluding . and .., 

@dirs=grep { -d } <*>,  <.[^.]>,  <.[^.]?*> ;

You can then print them, if that's the ultimate goal,
with
	print "@dirs\n";

> 
> -Todd
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>  SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
>         Email to majordomo at pm.org: ACTION spug-list your_address
> 
> 

-- 
*========================================================================*
| Tim Maher, PhD  Consultix &              (206) 781-UNIX/8649           |
|  Pacific Software Gurus, Inc             Email: tim at consultix-inc.com  |
|  UNIX/Linux & Perl Training              http://www.consultix-inc.com  |
| 2/22: UNIX  2/28: Perl Modules  2/29: Int. Perl  3/3: Pattern Matching |
*========================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list