Google Answers Logo
View Question
 
Q: How do I use File::Find? ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: How do I use File::Find?
Category: Computers > Programming
Asked by: bozo0-ga
List Price: $5.00
Posted: 22 Sep 2004 08:11 PDT
Expires: 22 Oct 2004 08:11 PDT
Question ID: 404704
I am using PERL v5.6.1 built for MSWin32-x86-multi-thread
from ActiveState.  The operating system is XP.  I would like
a script to search my C: drive for all the files named 
TESTTMP.TXT.  How can I get a script below to work?

use strict;
use File::Find;
find (\&matchPattern, 'C:/perl');  
print "Search whole C: drive\n";
find (\&matchPattern, 'C:/');  
sub matchPattern                      
{
    if ($File::Find::name =~ m"TESTTMP.TXT") 
    {
         print "$File::Find::name\n"; 
    }
}

This is the output I got:

C:/perl/TESTTMP.TXT
C:/perl/eg/TESTTMP.TXT
Search whole C: drive
C:/TESTTMP.TXT

This is the output I wanted but did not get:

C:/perl/TESTTMP.TXT
C:/perl/eg/TESTTMP.TXT
Search whole C: drive
C:/TESTTMP.TXT
C:/perl/TESTTMP.TXT
C:/perl/eg/TESTTMP.TXT
Answer  
Subject: Re: How do I use File::Find?
Answered By: palitoy-ga on 22 Sep 2004 09:22 PDT
Rated:5 out of 5 stars
 
Hello bozo0-ga

I think this is the script you require:

use strict;
use File::Find;
find (\&matchPattern, '/perl');
print "Search whole C: drive\n";
find (\&matchPattern, '/');
sub matchPattern
{
    if ($File::Find::name =~ m"TESTTMP.TXT")
    {
         print "C:$File::Find::name\n";
    }
}

If you have any further queries on this subject please ask for
clarification and I will do my best to respond quickly.
bozo0-ga rated this answer:5 out of 5 stars and gave an additional tip of: $2.00
Works perfect - thanks

Comments  
Subject: Re: How do I use File::Find?
From: palitoy-ga on 22 Sep 2004 10:20 PDT
 
Thanks for the 5-star rating and tip!  They are both appreciated.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy