使用shutil.copyfile,我得到一个Python IOError:[Errno 13]权限被拒绝: [英] using shutil.copyfile I get a Python IOError: [Errno 13] Permission denied:

查看:436
本文介绍了使用shutil.copyfile,我得到一个Python IOError:[Errno 13]权限被拒绝:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些使用shutil.copyfile的python代码:

I have some python code using shutil.copyfile:

import os
import shutil

src='C:\Documents and Settings\user\Desktop\FilesPy'
des='C:\Documents and Settings\user\Desktop\\tryPy\Output'

x=os.listdir(src)
a=os.path.join(src,x[1])

shutil.copyfile(a,des)
print a

它给我一个错误:

IOError: [Errno 13] Permission denied: 'C:\\Documents and Settings\\user\\Desktop\\tryPy\\Output'

为什么我没有复制文件的权限?

Why don't I have permission to copy the file?

推荐答案

来自 shutil.copyfile的文档:

将名为src的文件的内容(无元数据)复制到名为src的文件中 dst. dst必须是完整的目标文件名;看一下shutil.copy() 用于接受目标目录路径的副本.如果src和dst是 相同的文件,引发错误.目标位置必须是 可写否则,将引发IOError异常.如果dst 已经存在,它将被替换.特殊文件,例如字符 或使用此功能无法复制块设备和管道. src dst和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 shutil.copy() for a copy that accepts a target directory path. If src and dst are the same files, Error is raised. The destination location must be writable; otherwise, an IOError exception will be raised. If dst already exists, it will be replaced. Special files such as character or block devices and pipes cannot be copied with this function. src and dst are path names given as strings.

所以我想您需要使用 shutil.copy 或将文件名添加到des:

So I guess you need to either use shutil.copy or add the file name to des:

des = os.path.join(des, x[1])

这篇关于使用shutil.copyfile,我得到一个Python IOError:[Errno 13]权限被拒绝:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆