On Tue, Dec 2, 2008 at 06:48, Koti <[EMAIL PROTECTED]> wrote:
> Hi Matt, A very Good Morning, Need a small Info for my problem.
>
> I have a directory named "X" which has many sub directories
> "Y","Z","W" and many files about 20 , and these sub directories also
> contain some more sub directories and files in them and those sub
> directories also contain more directories and files.
>
> I want to read all the files that exists across all the  directors,
> subdirectories (only files list)  and need to display .
>
> i tried until 2 loops , but unable to complete the logic well on a
> whole. can u help me if u have any idea ,
snip

You should use File::Find* and the filetest operators**:

#!/usr/bin/perl

use strict;
use warnings;
use File::Find;

my @dirs = ("."); #list of directories to look in

File::Find::find(
        sub {
                if (-d) {
                        print "$File::Find::name is a directory\n";
                        return;
                }
                if (-f) {
                        print "$File::Find::name is a regular file\n";
                        return
                }
                print "I don't know what $File::Find::name is\n";
        },
        @dirs
);

* http://perldoc.perl.org/File/Find.html
** http://perldoc.perl.org/functions/-X.html


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to