Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Open a folder

by clueless newbie (Hermit)
on Jan 08, 2013 at 16:49 UTC ( #1012279=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^3: Open a folder
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2015-07-31 16:17 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 (279 votes), past polls