The way that your code is structured, the only file in the directory that will be analyzed is the first one, technically ".".
try this:
opendir(DIR, "/users/foo/")
|| die "Whoops!";
@bar = readdir(DIR);
closedir(DIR)
|| warn "Unable to close DIR";
splice(@bar, 0, 2); #get rid of '.' and '..'
And now, @bar contains all of the file names in directory '/users/foo/'. You can then use a
foreach loop or whatever to analyze the contents of that array line by line.
Hope that helps,
higle
Update: Feel free to omit the
splice bit in the above snippet for possible portability concerns. (though, this bit has been an integral part of a batch process that has been running flawlessly on my HP/UX machine every day for the last year or so, the song may not be the same for other OS flavors). I thought I'd throw that in to clean up the data, but it's not necessary for the example. Tip o' the lid to
merlyn.
Update++: In addition, my little pre-lunch break, thirty-second hack (indeed, it was hacked together in the few seconds I had before my coworkers left me to starve) has recently become the subject of another thread... It was brought up that it had absolutely
no error-checking, and indeed used a dubious hack to snip the dot and dotdot out of the array. I've replaced my nasty
for loop with a nice, tidy
splice command, and added perfunctory error checking to the
opendir and
closedir commands. I omitted those at first because I assumed they were rhetorical in such an abstract example. Assumption is the mother of all... etceteras. :)