I'm traversing a directory tree using Python 2.7.x, getting the file and directory sizes as it traverses. The problem I'm running into is that it is mistaking alias files for directories, and then throwing an error that there's "No Such File or Directory".
Code below:
def get_size(start_path = '.'):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
for dirName, subdirList, fileList in os.walk(rootDir, topdown=False):
dirSize = get_size(dirName) #this throws an error on alias files
for fname in fileList:
#do other things
I tried os.path.isdir() as well and that doesn't work. Further, I tried
return File.FSResolveAliasFile(path, True)[0].as_pathname()
But that doesn't seem to pick up all the alias files.
Any thoughts?