Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Get File list from the path

by Anonymous Monk
on Apr 23, 2008 at 18:52 UTC ( [id://682456]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

Could please advise me. How to get list file name in directory(including sub directory) with path in windows?

Replies are listed 'Best First'.
Re: Get File list from the path
by pc88mxer (Vicar) on Apr 23, 2008 at 19:13 UTC
    I'm guessing you want a list of all files in a directory including those in sub-directories.

    If so, the following will work under Windows and Unix systems:

    use File::Find; my @list; find(sub { push(@list, $File::Find::name) }, "/your/path"); # @list contains all file objects at and under /your/path
    To include only files, modify as follows:
    find(sub { -f $_ && push(@list, $File::Find::name); 1 }, "/your/path") +;
      another alternative would be to use File::Util
      use File::Util; my($f) = File::Util->new(); my($dirs, $files) = $f->list_dir('your/root/directory', qw/--recur +se --as-ref/);
      see File::Util for details
Re: Get File list from the path
by hydrodog (Novice) on Apr 23, 2008 at 19:19 UTC
    If it's just a fixed depth, the quick way is globbing:
    my @list = <dir/*.dat>; print join("\n", @list);
    for a recursive solution, the only way I know is to used opendir, readdir, closedir and write a recursive subroutine processing the files one at a time.
Re: Get File list from the path
by ferreira (Chaplain) on Apr 24, 2008 at 15:20 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://682456]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found