前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[已解决]python FileNotFoundError: [WinError 3] for getsize(filepath)

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

作者头像
hankleo
发布2020-09-17 11:23:12
1.5K0
发布2020-09-17 11:23:12
举报
文章被收录于专栏:Hank’s BlogHank’s Blog

问题代码:

代码语言:javascript
复制
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) 

报错:

代码语言:javascript
复制
  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:

解决:

代码语言:javascript
复制
filePath = u"\\\\?\\" + filePath
fileSize = getsize(filePath)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-04-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档