2014-10-03 158 views
0

我想從一個文件夾複製文本文件到另一個在Python中使用shutil。我寫了下面幾行:shutil返回IOError:[Errno 2]沒有這樣的文件或目錄

import shutil 
path_to_text= 'C:\pyprog\sample.txt' 
dest = 'C:\pyprog\dest' 

但每次我把這個代碼時,我得到errno的2.錯誤的回溯是

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python26\lib\shutil.py", line 88, in copy copyfile(src, dst) File "C:\Python26\lib\shutil.py", line 52, in copyfile fsrc = open(src, 'rb') IOError: [Errno 2] No such file or directory: 'C:\\pyprog\\sample.txt'

文件存在這樣也許我做的東西錯誤。我錯在哪裏?

+2

確保您的文件是不是叫'sample.txt.txt'。 Windows喜歡這樣做。 – 2014-10-03 14:18:01

+1

邪惡的窗戶。你是對的。謝謝。 – 2014-10-03 14:19:07

+0

,但現在我得到了拒絕的{IOERROR} [errno 13]權限:\\ pyprog' – 2014-10-03 14:32:00

回答

0

確保

shutil.copyfile(src, dst) 

shutil.copyfile(dst, src) 
相關問題