gpt4 book ai didi

python - 使用 shutil.copyfile 我得到一个 Python IOError : [Errno 13] Permission denied:

转载 作者:太空狗 更新时间:2023-10-29 17:55:56 30 4
gpt4 key购买 nike

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

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'

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

最佳答案

来自documentation shutil.copyfile 的:

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:

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

关于python - 使用 shutil.copyfile 我得到一个 Python IOError : [Errno 13] Permission denied:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11278066/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com