From: Matt Armstrong Date: 2002-03-20T01:10:23+09:00 Subject: Re: dots in Dir.entries Garance A Drosihn writes: > If a script is going thru a directory looking for all of its > sub-directories, it can keep a count of how many directories it has > already seen (including '.' and '..'). When that count is the same > as the link count, the script will know that it has found all the > sub-directories. It can therefore skip reading all the remaining > entries in the directory, because they must be files. [...] > If ruby always filters out the '.' and '..', then there is no way > for a script to perform this trick, because there will be no way for > the script to know when the '.' and '..' are processed. I think this is incorrect. Such a script could just initialize its "directory seen count" to 2 instead of zero to account for the missing '.' and '..'. This would actually be ever so slightly faster in the obscure case where the '.' and '..' directories are returned last. The script can bail out before it ever reads them. :) So this is an example where filtering '.' and '..' would cause some minor extra work for a script doing this optimization. But the filtering doesn't make it impossible or difficult. > [I think there is at least one more example where it is useful to > explicitly get the '.' and '..', but I do not remember it at the > moment] If you think of it, please post it! I can't think of a case where it would be impossible for a script to artificially include '.' and '..' when iterating directory entries. This is more inconvenient for the uncommon case, and convenient for the common case. -- matt