繁体   English   中英

WindowsError(3,'系统找不到指定的路径')

[英]WindowsError(3, 'The system cannot find the path specified')

有时在下面的行中收到以下异常:

WindowsError(3, 'The system cannot find the path specified')

总共大约有1956个pdf文件(在先前定义的路径中),并且在其中的43个上引发了异常。 我没有在例外的路径和文件名中看到任何模式。
关于问题是什么建议?

totalBytes = 0
if pdfFile.endswith(".pdf") and \
   (" permit " in pdfFile or " Permit " in pdfFile): 

    filename = os.path.join(root, pdfFile)
    try:
        absolutePath = os.path.abspath(filename)
        print ("absolutePath", absolutePath)
        # exception on this line, occasionally:
        numberOfBytes = os.path.getsize(absolutePath)
        print ("numberOfBytes", numberOfBytes)
        totalBytes += numberOfBytes
    except WindowsError as windowsError:
        print (windowsError, filename)

您应该能够通过一个怪异的技巧来绕过256个字符的限制:在绝对文件名前加上\\\\?\\ 当然,转义那些斜杠: "\\\\\\\\?\\\\"

另请参阅: 命名文件,路径和命名空间 TL; DR,不同的文件名解析器用于以\\\\?\\开头的名称,但具有不同的限制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM