At 04:38 PM 10-05-01 +0530, Amarnath Honnavalli Anantharamaiah wrote:
>Ho do I traverse the directory tree and find the file present in it.
>I mean I should have an output similar to find command in shell.
>
>e.g find . -name lock -print

Find("/etc", "abcd");

sub Find($$)
   {
   my ($sPath, $sMatch) = shift(@_);
   opendir(DIR, $sPath);
   # Get all files in folder
   my @asFiles = grep { -f "$sPath$_" && /$sMatch/ } readdir(DIR);
   my @asFolders = grep { -d "$sPath$_" && $_ !~ /^\.{1,2}$/ } readdir(DIR);
   closedir DIR;
   foreach my $sFolder (@asFolders)
     {
     Find($sFolder);
     }
   foreach my $sFileName (@asFiles)
     {
     my $sPathFileName = "$sPath/$sFileName";
     print "$sPathFileName\n";
     }
   }

Reply via email to