-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 2, 2008, at 5:48 AM, Koti 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 ,

You might want to read up on recursion.   Try something like this:

sub directory {
        my $directory = shift;

        opendir(DIR, $dir) || die "Unable to open the directory";
        @contents = readdir(DIR);
        close(DIR);

        foreach $listitem (@contents ) {
                if ( -d $listitem ) {
                        print " It's a directory!\n";
                        directory($directory.'/'.$listitem);   # This is 
recursion...
                }
                else {
                        print $l2;
                        print " It's a file!\n";              
                }
        }
}

print "Enter The Directory Path";
$dir = <STDIN>;
chomp($dir);
directory($dir);


This should work for what your trying to do, but I haven't actually tested it. I think you will get the idea.


Sincerely,
James Moser
[EMAIL PROTECTED]

There are 10 kinds of people in the world.
Those who understand binary, and those who do not.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkk1U58ACgkQBNt7jTp4/nmXeACg1kOIkzpb3G1eQEDzpNQTq8UX
AJkAnisqGkLwLPDAz/K3f8pZoCD30Vew
=BMWP
-----END PGP SIGNATURE-----

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


Reply via email to