Click to See Complete Forum and Search --> : Perl question


Scriptage
06-19-2003, 11:55 AM
Can someone tell me how to find directories within a directory please?

For example: I have a directory called directory1 with sub directories directory2 and directory3;

Can you please tell me how to "find" the subdirectories in directory1?

If that makes sense...

I've tried to use grep but to no avail.

Any help is greatly appreciated.

Regards

jeffmott
06-19-2003, 01:20 PM
Do you mean to list all subdirectories immediately under Directory1?my @dirs = grep -d, glob 'Directory1/*';
# returns ['Directory1/directory2', 'Directory1/directory3']

my @dirs = map m|([^/]*)$|, grep(-d, glob 'Directory1/*');
# -or-
chdir 'Directory1';
my @dirs = grep -d, glob '*';
# or you can use opendir and readdir
#returns ['directory2, 'directory3']**note. all examples above untested

Scriptage
06-19-2003, 06:51 PM
Cheers Jeff...
Yeah, I meant all subdirectories immediately under directory1...thanks very much for the help...it's been puzzling me for days!!

Thanks once again
regards
Carl