我正在尝试使用python中的shutil将文本文件从一个文件夹复制到另一个文件夹。我写了以下几行:
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'
文件存在,所以我可能做错了。我哪里弄错了?
答案 0 :(得分:0)
确保
shutil.copyfile(src, dst)
不
shutil.copyfile(dst, src)