【发布时间】:2012-03-19 00:49:16
【问题描述】:
我正在尝试在 Windows 下执行简单的文件复制任务,但遇到了一些问题。
我的第一次尝试是使用
import shutils
source = 'C:\Documents and Settings\Some directory\My file.txt'
destination = 'C:\Documents and Settings\Some other directory\Copy.txt'
shutil.copyfile(source, destination)
copyfile 找不到源和/或无法创建目标。
我的第二个猜测是使用
shutil.copyfile('"' + source + '"', '"' + destination + '"')
但它又失败了。
有什么提示吗?
编辑
生成的代码是
IOError: [Errno 22] Invalid argument: '"C:\Documents and Settings\Some directory\My file.txt"'
【问题讨论】:
-
对我来说似乎并不明显。也许你应该证明这一点。
-
考虑在内。我删除了那个无用的词。
-
不要只删除这个词,删除所有你的假设。没有理由仅仅因为空格而失败。
标签: python windows file-copying