Re: "." and ".." returned by dir()
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Sep 02, 2006
- 591 views
On Thu, 31 Aug 2006 16:59:51 -0700, "Ricardo M. Forno" <guest at RapidEuphoria.com> wrote: >I don't know for shure, but methinks that DOS returns the files and the >directories ordered by date. >If this is always true, it might be that you have some files dated earlier >than the directories where they reside, so this may not be always true. >This can happen if you create a directory and then you move some files to it. A quick test showed that false (on win98). Another quick test I tried kinda proved my theory: I created a.txt I created b.txt I deleted a.txt I created c.txt dir() now lists c before b. Basically, it prints the internal table, and it (the o/s) won't move files it don't have to. A second quick test involved my test directory, containing t01..t26; I created a new subdir, copied all the files into it, deleted t04, created a new file, and lo and behold, the new file landed in the slot left by t04. (ymmv) There is a pretty obvious implication for the . and .. entries which must be created first. Bottom line is . and .. /will/ (probably) always appear at the top of dir() [on win98], because there is little/no reason for the os to ever move them -- but that may not be true on NT/XP/Vista/Linux, etc: the better bet is, indeed and of course, to code more safely. If the hidden question was 'should I run back and modify several dozen programs which made this assumption?', I'd say no. Regards, Pete