Python to obtain files
Common attributes: Size, modification time, etc;
Remove the readonly attribute of the file;
For Windows files, you can obtain the archive and version information of the files;
Code:
Import OS
Def Testfileattributes ():
# This function is platform indepedent.
Statinfo = OS. Stat ( " C: \ python26 \ python.exe " )
Print Statinfo. st_size
Print Statinfo. st_atime
Print Statinfo. st_mtime
Print 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
Print Bool (fattrs & Win32con. file_attribute_readonly)
Testwinfileattributesifreadonly ()
# False
Def Testwinfileattributesifhidden ():
# This is just for Windows.
Fattrs = WIN32API. getfileattributes ( " C: \ python26 \ python.exe " )
# Print fattrs
Print 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 ' ]
Print Hiword, loword (MS), hiword (LS), loword (LS)
Get_version_number ( " C: \ Program Files \ 7-zip \ 7z.exe " )
# 9 20 0 0
Complete!