Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to find out all the text files in a given directory

Status
Not open for further replies.

michael3

Programmer
Aug 8, 2001
26
US
Hi,

I need to find out ONLY all the text files (*.[hc], and scripts) in a given directory (which may have a lot of sub-, sub-sub-, ...), using Perl. Following is my sample code, but it gave me all kind of files (*.o, *.a). Instead of -d, is there any other options I can use just for text file?

Any thought is greatly appreciated.

Michael

---

use File::Find;

sub change {

if ( -d ) {
print "\nIn directory: $_ \n";
}

if( -f ) {
print " -- $_ \n";
}
}

my @dirs = qw(.);

if ($#ARGV+1 == 0) {
find ( \&change, @dirs );
}else {
print "Usage: prinfile.pl!";
exit;
}
---

 
Try the '-T' flag instead of '-f'. See the perlfunc perldoc for more details.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top