2014-04-22 4 views
1

가끔아래 줄에 다음과 같은 예외를 받고 있어요 :WindowsError (3, '지정된 경로를 찾을 수 없습니다')

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

약 1,956 PDF 파일의 한 곳을 (에 경로가 이전에 정의 된) 예외가 43 개에 throw됩니다. 예외가있는 파일 이름 & 경로에 패턴이 표시되지 않습니다.
문제가 무엇인지 제안 해주세요.

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) 

답변

4

당신은 하나의 이상한 트릭과 함께 256 자 제한을 극복 할 수 있어야한다는 : 절대 파일 이름에 \\?\ 앞에 추가. 당연히 그 슬래시를 탈출하십시오 : "\\\\?\\".

다음을 참조하십시오 : Naming Files, Paths, and Namespaces. TL, DR의 경우 다른 제한 사항이있는 \\?\으로 시작하는 이름에 다른 파일 이름 분석기가 사용됩니다.

+0

web2py에서 일부 코드로 작업하는 동안이 문제가 발생했습니다. 귀하의 답변 덕분에 그것을 해결할 수있었습니다. –

관련 문제