Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Finding files in one directory

by bimleshsharma (Beadle)
on Dec 18, 2012 at 10:53 UTC ( #1009339=note: print w/ replies, xml ) Need Help??


in reply to Finding files in one directory

readdir function is good way to go ahead. Here is sample code you can use and modify as per your requirement

sub findfile { my $searchfile= shift; my $pathofbasedir= shift; opendir DIR,"pathofbasedir"; my @usefulfiles = grep{!/^\.{1,2}$/} readdir DIR; my @fileswithfullpath= map{$basepath."/".$_}@usefulfiles; closedir(DIR); foreach my $file (@fileswithfullpath) { if(-d $file) { findfile($searchfile,$file) } else { if( $file =~ /$searchfile/) { print "FIle exists at ",$file; exit(1); } } } }


Comment on Re: Finding files in one directory
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2015-07-07 21:19 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 (93 votes), past polls