

managing a subdirectory stack and processing that in a single loop). Bug reports are welcome I'm happy to update this if you can't get it working on your AIX or OS/400 or whatever.Īs you can see, it's much more complicated than the original and necessarily so: at least one function must exist to be called recursively unless you want the code to become very complex (e.g. I wrote this and tested it on 64-bit Linux, but it should work on any POSIX-compliant system, including Microsoft Windows.

Since it's clear some folks want to know how to do all this, I have a lot of comments in the code to try to make it obvious what's going on. That last one, dircnt, is the program compiled from the above source.ĭue to popular demand, I've re-written this program to be recursive, so it will drop into subdirectories and continue to count files and directories separately. Printf("%s contains %ld files\n", argv, count) įrom my testing without regard to cache, I ran each of these about 50 times each against the same directory, over and over, to avoid cache-based data skew, and I got roughly the following performance numbers (in real clock time): ls -1 | wc - 0:01.67 The fastest way is a purpose-built program, like this: #include
