Perl program to read a directory recursively and locate files with name matching a string provided.

Perl program to read a directory recursively and locate files with name matching a string provided.

————————————————————————————————————————-

————————————————————————————————————————-

use strict;
use warnings;

my $dir_name = shift;
my $search_str = shift;

&Dir_Files (dir => $dir_name, search_str => $search_str);
sub Dir_Files {
my %args = @_;
my $directory = $args{dir};
my $search_str = $args{search_str};
# my $directory = ‘c:\windows’;

opendir(DIR,$directory);
my @files = readdir(DIR);
closedir(DIR);
foreach(@files){
if ($_ =~ /$search_str/i) {
print “File name with $search_str found: “;
}
print $_,”\n”;
}
}

————————————————————————————————————————-

————————————————————————————————————————-

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: