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

Read only Files in a Directory

Status
Not open for further replies.

Newbee21369

Programmer
Oct 13, 2004
30
0
0
US
I'm trying to read only files in a directory. I have tried the code below but still having issues. Any suggestions?
#### Need to keep this code unchanged
opendir DIR, "Whatever/path";
@files=grep { !/^\.+$/ } readdir(DIR);
closedir DIR;

####Need to return only files in code shown below. I have tried -f $file, !-d $file, -e$file in my if condition and it is still returning Files and directories.

foreach $file (@files)
{
if (-f $file)
{
#print whatever
}
}
 
You're checking -f $file from the current directory. $file doesn't exist relative to your script, it exists inside of "Whatever/path"

Code:
if (-f "Whatever/path/$file")
 
DUH!!!!!!!!!! Thanks for keeping my head on straight!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top