Gan Uesli Starling wrote:
> 
> Am wanting to get a list of files in a directory, but only
> files which are not themselves further sub-directories.
> 
> When I do this...
> 
>     opendir(DIR, $this_path) or die "Can't opendir $this_path: $!";

You are opening the directory with opendir() but you are not reading the
files with readdir().

>     @file_list = glob("*");

If you use glob() then you don't have to use opendir() and closedir().


>     closedir(DIR);
> 
> ...it gives all the files, including the files which are also
> directories. Now on UNIX I can get a long list of all files, then grep
> out the directories, then sed out all but the names on every line. That
> works like so on NetBSD...
> 
> $file_list = `ls -l | grep -v "^d" | sed 's/.* //g'`;
> @file_list = split /\n/, $file_list;
> shift @file_list;
> 
> ...which does exactly what I want. It lists the files which are not
> directories.
> 
> But I am writing in Perl so as to NOT be OS dependent. I looked into the
> -d test. But it seems an awful kludge to have to open every file and get
> a status on it.

You don't have to open the file just to use stat() or the file test
operators.


> Is there a pure Perl way to get a list of file names exclusive of any
> sub-directory names that will work multi-platform?

Using opendir(), readdir() and closedir():

opendir DIR, $this_path or die "Can't opendir $this_path: $!";
my @file_list = grep !-d, readdir DIR;
closedir DIR;


Using glob():

my @file_list = grep !-d, glob "$this_path/*";



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to