A function for returning sum of the sizes of its arguments which could be single file/directory or a list of files/directories, is given below. The code gives an error message RuntimeError: maximum recursion depth exceeded while calling a Python object however I try to test this.
How to fix this?
Thanks
suresh
#!/usr/bin/python3.1
import os
def fileSizes(f):
if hasattr(f,'__iter__'):
return sum(filter(fileSizes,f))
if os.path.isfile(f):
return os.path.getsize(f)
elif os.path.isdir(f):
total_size = os.path.getsize(f)
for item in os.listdir(f):
total_size += fileSizes(os.path.join(f, item))
return total_size
os.listdir()does not include current or parent directory.