Python。 IOError:[Errno 13]权限被拒绝:当我复制文件时

问题描述:

我有两个文件夹:In,Out - 它不是磁盘D上的系统文件夹: - Windows 7. Out包含“myfile.txt”我运行以下python命令:Python。 IOError:[Errno 13]权限被拒绝:当我复制文件时

>>> shutil.copyfile(r"d:\Out\myfile.txt", r"D:\In") 

Traceback (most recent call last): 
    File "<pyshell#39>", line 1, in <module> 
    shutil.copyfile(r"d:\Out\myfile.txt", r"D:\In") 
    File "C:\Python27\lib\shutil.py", line 82, in copyfile 
    with open(dst, 'wb') as fdst: 
IOError: [Errno 13] Permission denied: 'D:\\In' 

问题是什么?

+0

使用资源管理器,我可以做的myfile.txt的复制到文件夹 –

阅读docs

shutil.copyfile(src, dst)

Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name; look at copy() for a copy that accepts a target directory path.

+0

我试过'shutil.copy'但尽管如此,面临同样的错误。 – pyd

使用 shutil.copy代替shutil.copyfile

例如:

shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath) 

井questionis老,为Python 3.6 的新观众使用

shutil.copyfile("D:\Out\myfile.txt", "D:\In") 

,而不是

shutil.copyfile(r"d:\Out\myfile.txt", r"D:\In") 

r参数传递读取文件不可复制

+0

这个答案是错误的。 'r'表示_raw string_,意思是字符串中的“\”字面意思是“\”,不需要转义。 –