2014-10-03 110 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) 
相关问题