Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: get list of files matching part of file name

by zentara (Archbishop)
on Jul 11, 2012 at 14:23 UTC ( #981125=note: print w/ replies, xml ) Need Help??


in reply to get list of files matching part of file name

Here is a File::Find solution

#!/usr/bin/perl # non recursive case insensitive search down # thru current directory for pattern in filenames. use warnings; use strict; use File::Find; $|++; my $search = $ARGV[0] or die "need search pattern $!\n"; my $path = '.'; my $regex = qr/\Q$search\E/i; find (sub { #prevent recursion into subdirs my $n = ($File::Find::name) =~ tr!/!!; #count slashes in file return $File::Find::prune = 1 if ($n > 1); return if -d; # return unless (-f and -T ); # limit to text files print "$File::Find::name\n" if /$regex/; }, $path);

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh


Comment on Re: get list of files matching part of file name
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981125]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-05 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls