On Thu, Jun 07, 2001 at 11:16:36AM -0500, Evan McNabb wrote:
>
> I've been working on a little script for a while but I can't seem to get
> this part working. What I want to do is list all of the *.jpg files in a
> directory (ls *.jpg) and then have an array with each filename as elements
> of that array. Its probably easy but I just can't get it right yet... :-)
> Thanks for the help.
opendir(DIR, $dir) || die("Unable to open directory \"$dir\": \l$!.\n");
my @jpegs = grep /\.jpg$/, readdir(DIR);
closedir(DIR);
OR
chdir($dir) || die("Unable to chdir to \"$dir\": \l$!.\n");
my @jpegs = glob("*.jpg");
OR (for recursive searching)
use File::Find qw(find);
my @jpegs;
find sub { push(@jpegs, $File::Find::name) if -f && /\.jpg$/ } $dir;
$dir is your directory, @jpegs will contain a list of jpeg files (relative
to $dir). Adapt to taste.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--