in reply to Re: Reading directory structure?
in thread Reading directory structure?

Hi Grygonos,

While it "gets the job done", a couple things jumped out at me that I felt were important enought to comment on.

First of all, the big one: foreach (2..$#entries) Try running this on the root of your C drive, which doesn't have the "." and ".." entries. You'll miss the first two directories.

opendir DIR, 'c:/'; print join "\n", (readdir(DIR))[0,1]; __END__ output on my system: 2dvtllhn.sys ADOBEAPP
Also, it seems that . and .. are always listed first in the directory, but I've never seen it documented. I certainly wouldn't depend on it.

Second, using the -d test instead of if(opendir(TEST,$item)) to test for a directory would be more efficient as well as more readable.

Replies are listed 'Best First'.
•Re^3: Reading directory structure?
by merlyn (Sage) on Oct 13, 2004 at 08:42 UTC