002_025 Python 修改Windows上一系列文件的属性,如设置文件为只读、归档等

代码如下:

#encoding=utf-8

print '中国'

#修改Windows上一系列文件的属性,如设置文件为只读、归档等
#1.下载pywin32 http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/
#2.
import  os, win32con,win32api

thefile = 'testReadOnly.test'

f = open(thefile,'w')
f.close()

win32api.SetFileAttributes(thefile,win32con.FILE_ATTRIBUTE_READONLY)

#win32con.FILE_ATTRIBUTE_READONLY 为SetFileAttributes API的具体值可以百度查看

打印结果如下:

中国

你可能感兴趣的:(002_025 Python 修改Windows上一系列文件的属性,如设置文件为只读、归档等)