Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do a recursive find for files in directory structure?

Status
Not open for further replies.

Jimbo2112

IS-IT--Management
Mar 18, 2002
109
GB
Hi All,

I am hoping to use File::Find to run a simple recursive find routine on a directory structure for files that start with an underscore. I am used to using the find command in Unix which looks similar to find2perl in structure, but I have had no joy in converting this in Perl!

Can someone give me a few lines of code that emulate below?

use File::Find
$root ="point to start search from";
find "start point" "for these types of file" "output results to this file"

Cheers

Jimbo
 
Hi Jimbo,

From the documentation....

Code:
    find2perl / -name .nfs\* -mtime +7         -exec rm -f {} \; -o -fstype nfs -prune
produces something like:
Code:
    sub wanted {
        /^\.nfs.*\z/s &&
        (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_)) &&
        int(-M _) > 7 &&
        unlink($_)
        ||
        ($nlink || (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))) &&
        $dev < 0 &&
        ($File::Find::prune = 1);
    }

Oh -- and that example delete's files, just thought I'd mention that before someone uses it "as is" to try it out.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 

Code:
use File::Find;

find (\&wanted, "root folder");

sub wanted {
   /\.htm$/ or return;  # use any regex here to match types of files
   -f and push @array, $File::Find::name;  #push only file names into an array
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top