File::File looks like a useful tool but I don't
understand how to use it enough to turn on File::Find::prune.
This is the last iteration of my script...
#!/usr/local/bin/perl -w
use File::Find;
sub wanted {
-T &&
-s > 5120 &&
push(@files, $File::Find::name) &&
($File::Find::prune = 1);
}
find (\&wanted, '.');
foreach (sort @files) { print "$_\n"; }
exit;
It runs but it also lists files passing the tests that
are in the subdirectories. I would appreciate anyone to try
to explain what I am doing wrong or point me to more
information. (BTW, I'm running this on a unix box.)
TIA, rr
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Pretty crudy whacking away at your script on my part but (note for
testing I dropped the size 5120 -> 512 because I have only small files
in this directory):
--------
use File::Find;
my @files;
sub wanted {
(-T $File::Find::name) &&
(-s $File::Find::name > 512) &&
(push @files, $File::Find::name) &&
($File::Find::prune = 1);
}
find (\&wanted, '.');
foreach (sort @files) { print "$_\n"; }
exit;
---------
[user@ravel perl]$ perl -w finder.pl
./serv.pl
./sock_err.pl
----
[user@ravel perl]$ l serv.pl sock_err.pl
-rwxrw-r-- 1 user user 617 Dec 7 19:57 serv.pl
-rw-rw-r-- 1 user user 2749 Dec 7 21:38 sock_err.pl
----
[user@ravel perl]$ ls -F
2hash.pl client.pl* equiv.pl hh.pl randi.pl
sock_err.pl
CookBookA/ cmc.dll* finder.pl name.pl ref.pl ver.pl
CookBookB/ del.pl foobie pls.pl serv.pl*
----
Should be a better way to write it, but I'm rushing off to dinner...
(Good excuse, no? ;-)
Bob L.
--
Robert Lynch-Berkeley CA USA-r...@best.com
http://www.best.com/~rmlynch/
I meant to reply sooner but it's been a busy holiday! Thanks for a
working example but I'm more confused than ever. I decided to use your
script to build a recursive/non-recursive version. The first thing I did
was to remove the prune statement as a test...
#==========
use File::Find;
my @files;
sub wanted {
(-T $File::Find::name) &&
(-s $File::Find::name > 512) &&
(push @files, $File::Find::name);
}
find (\&wanted, '.');
foreach (sort @files) { print "$_\n"; }
exit;
#=========
I expected this to list files in the sub-directories but it
didn't. I'll keep playing with it and maybe the light bulb will
come on eventually.
Thanks again,
Robert R.