I am using File::Find in the code below to find the files from /home/user/data
path.
use File::Find;
my $path = "/home/user/data";
chdir($path);
my @files;
find(\&d, "$path");
foreach my $file (@files) {
print "$file\n";
}
sub d {
-f and -r and push @files, $File::Find::name;
}
As I am changing the dir path to the path from where i need to search the files but still it gives me the files with full path. i.e.
/home/user/data/dir1/file1
/home/user/data/dir2/file2
and so on...
but I want the output like
dir1/file1
dir2/file2
and so on...
Can anyone please suggest me the code to find the files and display from current working directory only?
Best Answer
The following will print the path for all files under
$base
, relative to$base
(not the current directory):