且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用shutil.copyfile,我得到一个Python IOError:[Errno 13]权限被拒绝:

更新时间:2023-11-25 20:08:52

来自 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])