From: Sean O'Dell Date: 2002-03-13T13:39:23+09:00 Subject: Re: Some potential RCRs "Bob Alexander" wrote in message news:3C8EC7F5.A4B702C7@rsv.ricoh.com... > On the topic of whether ".." and "." should be in our directory > listings: > > I don't think it really matters that those entries really exist in the > OS directory structure. What matters is what is useful in a programming > context. The ".." and "." entries are "bookkeeping" entries, > implementation artifacts. How often when scanning a directory do you > really want to see them? The directory contents are really the files and > directories in them. The parent and self directory are not really > "contents", even though technically they appear in the directory. > > Note that the Unix "ls" command omits them by default. > > Both Java and Python omit them from their directory listing methods. > > It is a nuisance to almost always have to explicitly skip them when > scanning a directory: > > for entry in Dir.entries("myDir") > next if ["..", "."].include?(entry) > ... > end > > Can someone suggest an argument as to why having them in the listed > entries is useful? That's because ls considers files beginning with '.' to be "hidden." It hides all files beginning with '.' by default. There is no real "hidden" attribute in unix, so it's accepted that files beginning with '.' are "hidden" files. In Ruby, if you want that same feature (ignoring "hidden" files), you have to test for '.' at the beginning of each file name as you iterate through the directory entries and deliberately ignore them. But most code doesn't do that; most code sees "hidden" files and ignores their hidden status. A good example of their usefulness would be a simple file browser, say an HTML-based file browser. Each file in a directory displayed shows date, mod time and size. By simply showing this information for each directory entry, you can display that information for the current directory and the parent directory without having to do anything particularly special. Also, if you attempt to chdir a directory the user selects (in other words, navigate), and the user selects '..', they can get to the parent directory. '.' and '..' aren't just artifacts. If the user has selected a directory, it's easier and more efficient to get your stat information from '.' than from Dir.cwd(), and it's easier to change to the parent directory by performing a chdir('..') than to grab the current working dir and parse it to find the parent to chdir to it. They're not just artifacts, and the file system reports them as directory entries, so while I agree it would be nice to have an option that automatically filtered them out, by default they should remain as most people expect them to be there. It's quite the norm that they appear in the directory. Sean