디렉토리 크기를 가져 오는 기능을 얻으려고합니다.경로가 갑자기 역 슬래시 됨
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
이유는 백 슬래시를 백 슬래시 않습니다를? 오류를 해결하려면 어떻게해야합니까?
나는 왜 그것이 \를 추가 할 것인지 확신 할 수 없다. 하지만 대신 "/"를 사용하려고 했습니까?일반적으로 대부분의 라이브러리와 언어가 포함 된 경로에서 더 잘 작동합니다. – TheSHEEEP
예, 똑같은 것을 반환합니다. 정확하게. – mirandalol
Windows Vista/7 및 사용 권한 문제와 같은 소리가납니다. 사용자의 외부 파일에 액세스하려고하기 때문에 ... – mensi