Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Opening a Directory

by jonjacobmoon (Pilgrim)
on Jan 19, 2002 at 02:04 UTC ( #139967=note: print w/replies, xml ) Need Help??

in reply to Opening a Directory

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://139967]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-04-14 20:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found