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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read files under directory without giving file name?

Status
Not open for further replies.
Joined
Apr 30, 2003
Messages
56
Location
US
I know to read a file you can use open () by giving the file name. However, the situation I have is that under /apps/as400 directory I have lots and lots of files. I need to read them one by one. I can not hard code the file name to open because I need to open the first file, perform some tasks, and then go to the next file to read it and perform some tasks. How will I able to achieve that? Does anyone have any ideas about it? Thanks.
 
Code:
opendir (DIR, "/apps/as400");
foreach my $file (readdir(DIR)) {
   next if $file =~ /^\./; # skip ., .., .htaccess, etc
   open (FILE, "/apps/as400/$file");
   my @lines = <FILE>;
   close (FILE);
}
closedir (DIR);
 
What are the tasks you need to perform?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top