@建议操作server服务器文件夹时可以映射网络驱动盘

import win32security
import ntsecuritycon as con

FILENAME = r'D:\tmp\acc_test'  #文件夹路径

sd = win32security.GetFileSecurity(FILENAME, win32security.DACL_SECURITY_INFORMATION)
dacl = sd.GetSecurityDescriptorDacl()

ace_count = dacl.GetAceCount() #显示具有文件夹权限用户(组)数量
print('Ace count:', ace_count)

for i in range(0, ace_count):
rev, access, usersid = dacl.GetAce(i)
user, group, type = win32security.LookupAccountSid('', usersid)
print('User: {}/{}'.format(group, user), rev, access)
User: user (0, 0) 1179817 #只有该文件夹,查看权限
User: admin (0, 0) 1245631 #只有该文件夹,修改权限
User: administrator (0, 3) 2032127 #此文件夹,子文件夹 全部权限

#删除文件夹权限
Now you are able to read old ACEs and deleting old ones is quite simple:
for i in range(0, ace_count):
dacl.DeleteAce(0)

#掉用add增加权限
And after that you can just add privileges by calling AddAccessAllowedAceEx() [MSDN]:
userx, domain, type = win32security.LookupAccountName ("", "your.user")
usery, domain, type = win32security.LookupAccountName ("", "other.user")

dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 3, 2032127, userx) # 完全控制 @中间3代表权限会被后面文件夹继承 0:不会
dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 3, 1179785, usery) # 只读权限

sd.SetSecurityDescriptorDacl(1, dacl, 0) #可能没有必要
win32security.SetFileSecurity(FILENAME, win32security.DACL_SECURITY_INFORMATION, sd)
I've taken numbers 3, 2032127 and 1179785 from the listing in first half of the script (before running the script I've set up privileges in Explorer->Right Click->Properties->Security->Advanced):
#

#
#例子
# try:
# permit = '1179817'
# acegroup = 'Users'
# folder = 'Z:\\50.测试文件夹\\01.2'
# sd = win32security.GetFileSecurity(folder, win32security.DACL_SECURITY_INFORMATION)
# dacl = sd.GetSecurityDescriptorDacl()
# user1, domain, type = win32security.LookupAccountName('', acegroup)
#
# permisson = int(permit)
# dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 0, permisson, user1) #中间的0 表示只有该文件夹 3表示此文件夹,子文件
# sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary
# win32security.SetFileSecurity(folder, win32security.DACL_SECURITY_INFORMATION, sd)
# except Exception as e:
# print(e)

#python 的os模块操控文件夹
#import os
#import shutil

# try:
# os.mkdir(r'Z:\50.测试文件夹\01.2') #新建文件夹
# except Exception as e:
# print(e)

# try:
# os.rename(r'Z:\50.测试文件夹\01.2',r'Z:\50.测试文件夹\01.3') #重命名文件夹
# except Exception as e:
# print(e)

# try:
# shutil.rmtree(r'Z:/50.测试文件夹/01.3') ##删除名文件夹
# except Exception as e:
# print(e)
PS.调用cmd操控文件夹
http://jingyan.baidu.com/article/d3b74d64c853081f77e60929.html 下载安装pywin32
#创建文件夹
def createfolder(request):
folder=r'Z:/50.测试文件夹/01.3'
result={}
try:
#用wmi连接到远程服务器
pythoncom.CoInitialize()
conn = wmi.WMI(computer=‘192.168.0.1’, user='user', password='user')
cmd_callbat=r"cmd.exe /c mkdir %s" % folder
conn.Win32_Process.Create(CommandLine=cmd_callbat) #执行bat文件
result['isSuccess']=True
result['message']=' 添加成功'
except Exception as e:
print(e)
result['isSuccess'] = False
result['message'] = ' 添加失败'+e
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(json.dumps(result))
return response

来源http://jingyan.baidu.com/article/f3ad7d0ffe8b1409c2345b43.html
http://www.programcreek.com/python/index/478/win32security

python 查看文件夹权限组和用OS模块操作文件夹的更多相关文章

  1. python中OS模块操作文件和目录

    在python中执行和操作目录和文件的操作是通过内置的python OS模块封装的函数实现的. 首先导入模块,并查看操作系统的类型: >>> import os os.name # ...

  2. Python OS模块操作文件和目录

    #-*-coding:utf-8-*- import os import shutil ###############OS模块############## #获得当前python脚本的工作目录 os. ...

  3. os模块操作文件

    os模块: path=os.path.join(os.path.dirname(os.path.dirname(__file__)),'images') path:运行脚本的当前文件下的上一个文件的地 ...

  4. python——os模块操作文件

  5. ubuntu chmod 无法更改 文件夹权限 系统提示“不允许的操作 2、linux 如何修改只读文件 3、ubuntu安装

    1.ubuntu chmod 无法更改 文件夹权限 系统提示“不允许的操作 答案:需要超级用户权限 sudo 2.linux 如何修改只读文件 答案:可以使用chmod命令,为改文件提供其他的权限.u ...

  6. 【python基础语法】OS模块处理文件绝对路径,内置的异常类型、捕获、处理(第9天课堂笔记)

    import os """ 通过文件的路径去打开文件 相对路径:相对当前的工作路径去定位文件位置 .:代表当前路径 ..:代表上一级路径(父级路径) 绝对路径:相对于电脑 ...

  7. os模块、文件压缩 、匹配文件后缀名:fnmatch glob

    一.os模块 os模块:是python是系统交互的模块 import os # 0平台信息的一些操作 python是夸平台的,所以内部兼容了不同的平台 1. os.name # 操作系统 nt是win ...

  8. python基础之os模块操作

    # os模块 目录相关内置库import os# . 当前目录 .. 返回上一级目录# 1. os.path.abspath() --获取当前文件的绝对路径(不包含os模块.py) pwd# path ...

  9. (原创)Python文件与文件系统系列(2)——os模块对文件、文件系统操作的支持

    os模块的功能主要包括文件系统部分和进程管理部分,这里介绍其中与文件系统相关的部分. 当请求操作系统执行操作失败时,os模块抛出内置异常 exceptions.OSError 的实例,可以通过 os. ...

随机推荐

  1. Linq101-Grouping Operators

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Groupin ...

  2. Activity之间的数据传递(Arraylist)

    1.使用Serialiable方法 实现序列化 2.使用Parcelable方法(这是android自己封装的类) Parcel类是封装数据的容器,封装后的数据通过Intent和IPC传递     实 ...

  3. mac在 aliyun linux ecs实例上安装 jdk tomcat mysql

    用了一个ftp 工具 把 gz rpm 等 传递到ecs 上 -- 用这个Transmit 用ssh远程登录,然后依次安装 jdk tomcat  mysql 到 /usr/local/... 设置环 ...

  4. iOS开发之通知中心(NSNotificationCenter)

    前言 面向对象的设计思想是把行为方法封装到每一个对象中,以用来增加代码的复用性.正是这种分散封装,增加了对象之间的相互关联,总是有很多的对象需要彼此了解以及相互操作! 一个简单示例说明这种交互产生的对 ...

  5. 微信小应用vs progressive-web-apps

    https://developers.google.com/web/progressive-web-apps/

  6. uvalive 5760 Alice and Bob (组合游戏,dp)

    题目链接: http://vjudge.net/problem/viewProblem.action?id=25636 对于>1的堆,必然会被其中一人全部合并. 然后就是二维dp,dp[非1堆的 ...

  7. 利用GDB在远程开发机进行调试

    由于一些环境的制约,很多同学都可能需要在开发机上进行调试,但由于开发机资源的限制,在开发机上直接进行本地的GDB环境配置就成了难题,这个时候其实我们可以利用GDB中自带的gdbserver工具就可以进 ...

  8. 数据库备份工具mysqldump重要参数详解

    1. --single-transaction InnoDB 表在备份时,通常启用选项 --single-transaction 来保证备份的一致性,实际上它的工作原理是设定本次会话的隔离级别为:RE ...

  9. 高效jQuery

    1.缓存变量 DOM遍历是昂贵的,所以尽量将会重用的元素缓存. // 糟糕 h = $('#element').height(); $('#element').css('height',h-20); ...

  10. java获得系统当前日期

    package com.web.test; import java.text.ParseException; import java.text.SimpleDateFormat; import jav ...