我正在尝试获取获取目录大小的功能。
def fsize(path, returntype='b'):
size = 0
if isdir(path):
for root, dirs, files in walk(path):
for file in files:
size += getsize(join(path,file))
else:
print abspath(path)
size = getsize(abspath(path))
if returntype != 'b':
return convert_size(size, returntype)
return size
path = r"D:\Library\Daniel's_Books"
print fsize(path, 'm')
我得到了这个有趣的错误:
size = getsize(abspath(path))
File "C:\Python27\lib\genericpath.py", line 49, in getsize
return os.stat(filename).st_size
WindowsError: [Error 2] The system cannot find the file specified: "D:\\Library\\Daniel's_Books\\cover.jpg"
D:\Library\Daniel's_Books\cover.jpg
为什么它反斜杠反斜杠?我该如何解决这个错误?