http://www.perlmonks.org?node_id=1012279


in reply to Re^2: Open a folder
in thread Open a folder

Since you mentioned File::Find ... Change the sub _SizeAndMD5 to suit your problem.

#! use strict; use warnings; use File::Find; use Digest::MD5::File; no warnings "File::Find"; use Smart::Comments; local *wanted=sub { if (-d $File::Find::name) { # directory } elsif ($File::Find::name =~ m{\.txt$}i) { # a file of interest print "for $File::Find::name - @{[_SizeAndMD5($File::Find::nam +e)]}\n"; } }; # wanted # Do something based on the file's content local *_SizeAndMD5=sub { my ($filename_S)=@_; return (-e $filename_S ? sprintf("%8.8lx-%32.32s",-s $filename_S,D +igest::MD5::File::file_md5_hex($filename_S)) : undef); }; # _SizeAndMD5: File::Find::find({ no_chdir=>1,wanted=>\&wanted },@ARGV); exit;

This will process all of the files with a ".txt" extension below the directories specified by @ARGV.