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

List files only in a directory

Status
Not open for further replies.

manutektips

Programmer
Sep 8, 2003
11
GB
Hi,
How do I list the files ( and not directories) in a given path. I want to run a loop where I want to process file by file. I want to read the content of one file, check something, close the file, move on to next file until all the files are processed in that given directory. Please help
 
Hi

manutektips said:
How do I list the files ( and not directories) in a given path.
The example in the manual at the [tt]readdir[/tt] command is close to what you want. Only have to change the condition.
Code:
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
@files = grep { ! -d "$some_dir/$_" } readdir(DIR);
closedir DIR;

Feherke.
 
Hi,
Thanks for the information. Does "grep" function work in windows
 
If you mean 'Does Activestate perl support grep()?', then yes.
 
perl has it's own grep() function, which is what feherkes code is using.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top