<?xml version="1.0" encoding="windows-1252"?>
<node id="15179" title="Getting a List of Files Via Glob" created="2000-05-28 01:25:04" updated="2005-07-27 06:44:56">
<type id="115">
perlquestion</type>
<author id="11052">
Zoogie</author>
<data>
<field name="doctext">
I need to get a list of files that fit a set of filename
globs input by the user.  The problem is, the files may
be in a different directory.  For example, if the user
enters:&lt;p&gt;

&lt;pre&gt;
  $area = "public/test/";
  @files = ("*.txt", "_*");
&lt;/pre&gt;

The function should return something like:&lt;br&gt;
&lt;pre&gt;
  readme.txt, files.txt, _index, _sortopts, ... etc.
&lt;/pre&gt;

I'm trying to use the glob function, but if you specify
another directory, that directory name is prepended to
every filename.  Here's my current function:&lt;p&gt;

&lt;pre&gt;
@file_list =
    map { /^$area(.*)/; $1 }
    glob(join(' ',map { $area.$_ } @files));
&lt;/pre&gt;

Works as expected, but that seems like a lot more work
than necessary.  Is there an easier / clearer / more
efficient way to do this?</field>
</data>
</node>
