Number of files in a directory?

Shane Bouslough shane at inferno.peri.com
Thu May 30 03:56:30 AEST 1991


>From article <1146 at mwtech.UUCP>, by martin at mwtech.UUCP (Martin Weitzel):
> In article <1991May19.111727.18637 at virtech.uucp> cpcahil at virtech.uucp (Conor P. Cahill) writes:
> :mikeh at fsd.cpsc.ucalgary.ca (Michael Hoffos) writes:
> :>[...]
> :>how can you get the number of
> :>files that are in a directory? 
> [...]
> :If on a v7 style filesystem you can get the size of the directory and
> :divide it by 16, but that only works on a single directory,  is non-portable
> :and definately doesn't work for BSD style file systems.
> 
> And it will not work if you have deleted some files from the directory,
> as directories don't shrink once they have been big (except you have a
> special utility to compress them).

However, if you're going to get the size of a directory, you'll probably
open it anyway, so why not just read each entry and count those not deleted?

> -- 
> Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83


-- 
Shane Bouslough    |  ...!rutgers!mcdhup!inferno!shane           516-467-0500
Periphonics Corp.  |                                             Ride Bike!
4000 Veterans Hwy. |  "We're talking Mega-Ecstasy-Bliss!!!"
Bohemia, NY 11716  |                              -David Lister, Red Dwarf



More information about the Comp.unix.questions mailing list