[已解决]python FileNotFoundError: [WinError 3] for getsize(filepath)

问题代码:

def sourceStatic(path, exclude):

    # exclude list convert to lower 
    exclude = list(map(lambda x:x.lower(), exclude))
    files_size = 0
    files_count = 0
    for root, dirs, files in os.walk(path):
        for fileName in files:
            fname, fileEx = os.path.splitext(fileName)
            fileEx = (fileEx[1:]).lower()
            if not any(fileEx in item for item in exclude):
                print(fileName)
                filePath = os.path.join(root,fileName)
                fileSize = getsize(filePath)
                files_size += fileSize
                files_count += 1

    # return multiple data as dictionary              
    ret = {}
    ret['files_size'] = size(files_size)
    ret['files_size_byte'] = files_size
    ret['files_count'] = files_count
    print(ret)
    return (ret) 

报错:

  File "C:\Python34\lib\genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
FileNotFoundError: [WinError 3] The system cannot find the path specified:

解决:

filePath = u"\\\\?\\" + filePath
fileSize = getsize(filePath)

转载于:https://www.cnblogs.com/hankleo/p/10788960.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值