How do I...

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";
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.