有时,我会在下面的一行中得到以下异常:
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)发布于 2014-04-22 21:17:47
您应该能够绕过256个字符的限制,使用一个奇怪的技巧:将\\?\添加到绝对文件名。当然,避开那些斜杠:"\\\\?\\"。
另见:命名文件、路径和命名空间。TL;DR,一个不同的文件名解析器用于以\\?\开头的具有不同限制的名称。
https://stackoverflow.com/questions/23229961
复制相似问题