2016-10-25 12 views
0

내 다운로드를 정렬하는 프로그램을 작성하려고합니다.파일 정렬 스크립트를 만들 때 오류가 발생했습니다.

Traceback (most recent call last): 
    File "/usr/lib/python3.5/shutil.py", line 538, in move 
    os.rename(src, real_dst) 
FileNotFoundError: [Errno 2] No such file or directory:'UntitledDocument.txt' -> 'Downloads/TxtFiles/UntitledDocument.txt' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/home/nicholas/Python/DownloadSorter.py", line 19, in <module> 
    shutil.move(file, folders[fileType]) 
    File "/usr/lib/python3.5/shutil.py", line 552, in move 
    copy_function(src, real_dst) 
    File "/usr/lib/python3.5/shutil.py", line 251, in copy2 
    copyfile(src, dst, follow_symlinks=follow_symlinks) 
    File "/usr/lib/python3.5/shutil.py", line 114, in copyfile 
    with open(src, 'rb') as fsrc: 
FileNotFoundError: [Errno 2] No such file or directory: 'UntitledDocument.txt' 

이것은 코드입니다 : 나는 그것을 실행하려고하면 그러나,이 얻을! # 문제가 있다고는/usr/빈/python3 수입 OS 수입

folders = { 
    '.tar.gz': 'Downloads/TarFiles', 
    '.deb': 'Downloads/DebFiles', 
    '.iso': 'Downloads/IsoFiles', 
    '.txt': 'Downloads/TxtFiles', 
    '.exe': 'Downloads/ExeFiles', 
    '.mp3': 'Videos', 
    '.wav': 'Music' 
} 
os.chdir('/home/nicholas/') 

for file in os.listdir('Downloads'): 
    for fileType in folders.keys(): 
     if file.endswith(fileType): 
      shutil.move(file, folders[fileType]) 

답변

0

또 shutil 경로없이 파일 이름을 사용하고 shutilDownloads 디렉토리의 작업 디렉토리에서 파일을 찾습니다.

수정은 간단하다 :

shutil.move(os.path.join('Downloads', file), folders[fileType]) 
+0

... 아직 대상 디렉토리가 실제로 존재한다고 가정. – tripleee

+0

당신 말이 맞아요. 그러나 우리는 한 번에 하나의 오류를 다루고 있습니다 :) – table

관련 문제