概述
通用属性:大小,修改时间等;
去掉文件的
readonly
属性;
对于
windows
文件,可以获得是否
archive
,文件的版本信息等;
代码:
import
os
def
TestFileAttributes():
# This function is platform indepedent.
statinfo = os.stat(
"c:\python26\python.exe"
)
statinfo.st_size
statinfo.st_atime
statinfo.st_mtime
statinfo.st_ctime
#statinfo also include other linux specific information.
#print statinfo
TestFileAttributes()
#27136
#1299820024.28
#1228458748.0
#1228458748.0
import
stat
def
TestForChangeToWrite(path):
# This is platform indepedent.
if
not
os.access(path,os.W_OK):
os.chmod(path,stat.S_IWRITE)
TestForChangeToWrite(
"c:\python26\python.exe"
)
##################################################################
import
win32api,win32con
def
TestWinFileAttributesIfReadonly():
# This is just for windows.
fattrs = win32api.GetFileAttributes(
"c:\python26\python.exe"
)
#print fattrs
bool(fattrs & win32con.FILE_ATTRIBUTE_READONLY)
TestWinFileAttributesIfReadonly()
#False
def
TestWinFileAttributesIfHidden():
# This is just for windows.
fattrs = win32api.GetFileAttributes(
"c:\python26\python.exe"
)
#print fattrs
bool(fattrs & win32con.FILE_ATTRIBUTE_HIDDEN)
TestWinFileAttributesIfHidden()
#False
from
win32api
import
GetFileVersionInfo, LOWORD, HIWORD
def
get_version_number(filename):
# This is just for windows.
info = GetFileVersionInfo(filename,
"\"
)
#print info
ms = info[
'FileVersionMS'
]
ls = info[
'FileVersionLS'
]
HIWORD (ms), LOWORD (ms), HIWORD (ls), LOWORD (ls)
最后
以上就是鲤鱼板凳为你收集整理的python实例属性怎么修改_python实例[查询修改文件的属性]===的全部内容,希望文章能够帮你解决python实例属性怎么修改_python实例[查询修改文件的属性]===所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复