From: Garance A Drosihn Date: 2002-03-20T01:42:34+09:00 Subject: Re: dots in Dir.entries At 9:10 AM -0700 3/19/02, Matt Armstrong wrote: >Garance A Drosihn writes: > > 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 '..'. >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. No. It is impossible. You can't just add 2 for '.' and '..', because the current directory may not have those (it depends on what kind of filesystem you are using). The reason I know about this trick is because the trick doesn't always work on AFS, due to the link-count being handled differently on AFS in some cases... :-) If I recall correctly, some CD-rom file systems also handle this differently. My main point being that the handling of '.' and '..' is not simply a matter of which OS you are on, but a matter of which type of filesystem you are looking at. Any script which does need '.' and '..' can not blindly put them there, while any script which does NOT need them can trivially remove them. (although technically I suppose the script should check to make sure they are a directory before ignoring them...) > > [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! Yeah, it bugs me that I can't remember it. When this topic originally came up I was going to reply with a different example, but I didn't have the time to write it out. This time I just happened to remember the above example due to something else I'm working on at the moment. I will admit that in 99.8% of the scripts that I've written, I have to filter out those two directories. But for the other 0.2%, I can't just blindly add them. The 'ls' command has both 'ls -a' and 'ls -A', where the only difference is whether those two are included in the listing. It might make sense for ruby to have both Dir.entries and some other method -- except that I can't decide on a good name for that other method... :-) Dir.entries_all ? -- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu