Ezilon.com - Target Your Audience, be Seen in Your Region

How do I...

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 117 posts

Joined: Mar 2000

Hey!

I need a little help. How do get the name of every file in a directory? They're all text files. So, could I use something like "*.txt"?

Thanks!

--Edge

They have: 161 posts

Joined: Dec 1999

Since you're using Perl, you could use a very-Perl approach:

opendir DIR, $path or die "can't read $path: $!";
@text = map "$path/$_", grep /\.txt$/, readdir DIR;
closedir DIR;

'

Or you could take the let-the-OS-do-it approach:

@text = glob "$path/*.txt";

'

Jeff japhy Pinyan -- accomplished Perl teacher, author, and hacker

Are you a Monk?
Perl Guru Forums
Visit #perl on DALnet