Count Files in a Directory
hokiegal99
hokiegal99 at hotmail.com
Sun Dec 21 18:45:31 EST 2003
I'm trying to count the number of files within a directory, but I
don't really understand how to go about it. This code:
for root, dirs, files in os.walk(path):
for fname in files:
x = str.count(fname)
print x
Produces this error:
TypeError: count() takes at least 1 argument (0 given)
for root, dirs, files in os.walk(path):
for fname in files:
x = list.count(files)
print x
TypeError: count() takes exactly one argument (0 given)
Also wondered why the inconsistency in error messages (numeric 1 vs.
one)??? Using 2.3.0
Thanks!!!
More information about the Python-list
mailing list