C
Charles Packer
In what order does readdir() see the
entries in a directory (in a Unix
environment)? I'm posting about this
as a sort of public service -- a search
shows that nobody's posted herein about
this gotcha.
Tests on several directories seemed to
indicate that "." and ".." always come
first. The examples in "Perl Cookbook"
and other places include a check for these
inside the loop...but hey, if I'm processing
directories with thousands of files, as in
while (defined($FileName = readdir(DIR))) {
seems not unreasonably anal to eliminate
those two pesky entries right away with two
premptive readdir() calls before entering
the loop, right? Bad idea!
entries in a directory (in a Unix
environment)? I'm posting about this
as a sort of public service -- a search
shows that nobody's posted herein about
this gotcha.
Tests on several directories seemed to
indicate that "." and ".." always come
first. The examples in "Perl Cookbook"
and other places include a check for these
inside the loop...but hey, if I'm processing
directories with thousands of files, as in
while (defined($FileName = readdir(DIR))) {
seems not unreasonably anal to eliminate
those two pesky entries right away with two
premptive readdir() calls before entering
the loop, right? Bad idea!