【问题标题】:How do I change permissions to allow a file to be copied to this directory?如何更改权限以允许将文件复制到此目录?
【发布时间】:2017-09-28 01:04:49
【问题描述】:

我有一个简单的脚本可以将文件的最新版本下载到本地机器。这是失败的代码的 sn-p。

....
d = "D:\\" + youngest[2]
if os.path.exists(d):
    shutil.rmtree(d)
os.mkdir(d)
os.chmod(d, stat.S_IWRITE)
shutil.copyfile(youngest[1] + "/EXE/FILE.EXE", d)
....

我得到的错误是:

PermissionError: [Errno 13] Permission denied: 'D:\23.5.2.224'

谷歌搜索后,os.chmod() 似乎是我更改此文件夹权限的门票。我做错了什么?

【问题讨论】:

    标签: python operating-system


    【解决方案1】:

    由于 D 驱动器,我假设您在 Windows 上。 Windows 上的 Chmod 不像在 Linux 操作系统上那样工作。看看这篇 Chmod issue to change file permission using python 的帖子,他们解释了一个可以帮助设置 Windows 权限的模块

    【讨论】:

    • 是的,我看到了。虽然我不确定如何将其应用于文件夹。
    • stackoverflow.com/a/12168268/7770917 试试这个。他使用win32模块设置文件夹权限
    • 有趣,我无法 pip install win32/pywin32/win32security
    • Could not find a version that satisfies the requirement pywin32 (from versions: ) No matching distribution found for pywin32 我假设这些对于 python3.6 不存在
    • 它可能最多支持 python 3.3,sourceforge 现在已关闭,我无法确认。确保 win32 和 python 都是 64 位或 32 位。如果这不起作用,这个模块可能只适用于 python 3.3 及以下版本,但这对我来说似乎很奇怪
    猜你喜欢
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多