Count Files in a Directory
hokieghal99
hokiegal99 at hotmail.com
Mon Dec 22 12:27:59 EST 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?
Thanks!!!
More information about the Python-list
mailing list