Perl Simple File Find

27 August 2008
by Gavin Colborne

The below example runs and simply prints the file names of files inside the c:temp folder, you will need to add the behaviour you require on the “print” line:
Command line call:
perl.exe c:temp

use strict;
use File::Find;
my ($area) = @ARGV;
my(@files, $file);
find(&wanted, $area);
		foreach $file(@files){
			if (-f $file){
				print "File: $filen";
sub wanted {
	push @files, $File::Find::name;
	return @files;

File: c:temp/find.txt
File: c:temp/find2.txt
File: c:temp/find3.txt
File: c:temp/find4.txt
File: c:temp/regfind.exe

Our Latest News