【发布时间】:2017-02-12 03:17:15
【问题描述】:
我正在尝试将文件从一个文件夹复制到另一个文件夹,但我收到“PermissionError: [Errno 13] Permission denied”。我在我的主目录中工作,我是 PC 的管理员。浏览了许多其他以前的帖子..尝试了我所知道的所有选项(编程新手)...需要一些帮助。
import os
import shutil
src = "C:\\Users\\chzia\\Scripts\\test" # the file lab.txt is in this folder that needs to be copied to testcp folder.
dst = "C:\\Users\\chzia\\Scripts\\testcp"
for file in os.listdir(src):
src_file = os.path.join(src, file)
dst_file = os.path.join(dst, file)
#shutil.copymode(src, dst) # i have tried these options too same error
#shutil.copyfile(src, dst) # i have tried these options too same error
shutil.copy(src, dst)
我的目标是创建一个 .exe,将文件从网络位置复制到运行 .exe 的 PC 上的特定文件夹中。 提前感谢所有的支持和帮助。
【问题讨论】:
-
包括确切的回溯——否则,当操作系统拒绝其请求时,我们不知道
shutil.copy()正在执行什么操作,并且无法判断任何给定的答案是否合理。如果您可以尝试自己手动(即从命令行)执行该操作并验证它是否有效,那也会很有帮助。