Count Files in a Directory
hokiegal99 at hotmail.com
Mon Dec 22 18:41:03 CET 2003
> def fs_object_count(setpath):
> file_count = 0
> dir_count = 0
> for root, dirs, files in os.walk(setpath):
> file_count += len(files)
> dir_count += len(dirs)
> return file_count, dir_count
> I'm using this. Thanks to all for the tips and corrections! It works
> very well on small sets of data (<= 5GB) it is very accurate on this
> data. On largeer (> 20GB) filesystems, the count will be off by 30 to 40
> objects. For example on one 22GB filesystem the OS thinks there are
> 100,222 objects in the path, Python thinks there are 100,260... Any
> ideas on this difference?
Woops... I spoke too soon. Just caught this difference on 4.4GB of data.
The os thinks there are 12,204 objects in the path while Python
thinks there are 12,205 objects.
More information about the Python-list