I have a directory containing thousand of file.
Suppose I have 3 pdf files having same name like:
- sample_Q1.pdf
- sample_Q2.pdf
- sample_Q3.pdf
Now I want to find the file list having particular name started with "Sample".
I'm currently using:
#!/usr/bin/perl
use strict;
use warnings;
my $dir = '/home/gaurav/Desktop/CSP';
opendir( DIR, $dir ) or die $!;
while ( my $file = readdir(DIR) ) {
# We only want files
next unless ( -f "$dir/$file" );
# Use a regular expression to find files ending in .txt
next unless ( $file =~ /\.pdf$/ );
print "$file\n";
}
closedir(DIR);
exit 0;