Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!husc6!cmcl2!polyof!john From: john@polyof.UUCP ( John Buck ) Newsgroups: comp.unix.wizards Subject: Re: Dot files always first in directory? Summary: RTFM, ls -f does it Message-ID: <462@polyof.UUCP> Date: 5 May 89 16:33:46 GMT Organization: Polytechnic University, Farmingdale NY Lines: 33 In article <11493@ulysses.homer.nj.att.com>, ekrell@hector.UUCP (Eduardo Krell) writes: > In article <2778@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: > >To beat this horse quite dead, any leading character that would sort before > >the period will place the filename before the . and .. in a directory > >listing. > That's because "ls" sorts the directory entries by default. The original > question was about readdir() which doesn't. Use "od" or write a small > program using opendir() and readdir() and you'll see that "." and ".." > are the first and second entries. The '-f' option of 'ls' lists directories (and other files, for that matter) in "directory order"; it performs NO sorting. Usually, '.' and '..' will appear first. This is not necessarily true; some wise-guy can easily change the order of things in directories using fsdb, or some other tool(s). The bottom line is, since you are readdir()ing anyway, how hard is it to add the test after each readdir? C'mon, it is not going to slow things down. An extra compare (or two) is worth the grief you may suffer later. After all, how many entries are in the directory? 1000? 2000? how long does 1 or 2K compares take these days? /* Notice this first compare will fail most of the time, and the * rest of this 'if' won't even get executed */ if(dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || (d->d_name[2] == '\0' && dp->d_name[1] == '.'))){ continue; } John Buck john@polyof.poly.edu