From: Garance A Drosihn Date: 2002-03-19T18:07:30+09:00 Subject: Re: dots in Dir.entries At 4:22 PM +0900 3/19/02, Yukihiro Matsumoto wrote: >Hi, > >Could you summarize pros and cons for filtering >dot files (. and ..) from Dir.entries and Dir.each, >please? Matt Armstrong already replied with a fair summary of what was said in the earlier thread. Or at least, what I saw of that thread. I am one of those who think the '.' and '..' should show up in ruby if the operating system routines would show them. For those file systems which do have them, then some scripts use them for a useful optimization trick. On a filesystem which does have these, a stat() call for any directory will always show at least two "links" to it. Those links come from the '.' and '..'. There is one additional link for each subdirectory (the '..' of that subdirectory). Files in the directory do not increase the link count. 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. When playing with directories that have hundreds or thousands of files, this can result in avoiding a huge amount of unnecessary work. 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. If ruby does not filter out the '.' and '..', then it is trivial for the script to do that filtering. [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] I agree that is a little annoying to have to filter those when you do not want them (which is most of the time), but there are situations where it is important that they are not filtered out. I would not mind if this was a different method name, but I do think it needs to be available. -- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu