使用python更改Windows中可写的目录 [英] Change directory writable in windows using python

查看:27
本文介绍了使用python更改Windows中可写的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在windows中,C盘内的目录可以通过编辑目录的安全属性手动更改为可写,为用户提供完全控制.如何在 Python 中做到这一点?

In windows, the directories inside the C drive can be changed into writable manually by editing the security attributes of a directory providing full control to the user. How this can be done in Python?

我的想法是:

import os, stat
my_dir = 'C:\\Program Files\\Java'
os.chmod (my_dir, stat.S_IWRITE)

但没有成功.

有人知道吗?

推荐答案

试试这个,

os.chmod(my_dir,0o777) # read and write by everyone
os.chmod(my_dir,0o755)  # read and write by me, readable for everone else

Python chmod 文档

注意 尽管 Windows 支持 chmod(),但您只能用它设置文件的只读标志(通过 stat.S_IWRITE 和 stat.S_IREAD 常量或相应的整数值).所有其他位都被忽略.

Note Although Windows supports chmod(), you can only set the file’s read-only flag with it (via the stat.S_IWRITE and stat.S_IREAD constants or a corresponding integer value). All other bits are ignored.

这篇关于使用python更改Windows中可写的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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