琴倾天下txt下载,俞敏洪经典语录,灌女友喝醉酒
1. 通过windows attrib 命令获取文件隐藏属性
key
+ : turn an attribute on
- : clear an attribute off
pathname : drive and/or filename e.g. c:\*.txt
/s : search the pathname including all subfolders.
/d : process folders as well
attributes:
r read-only (1)
h hidden (2)
a archive (32)
s system (4)
extended attributes:
e encrypted
c compressed (128:read-only)
i not content-indexed
l symbolic link/junction (64:read-only)
n normal (0: cannot be used for file selection)
o offline
p sparse file
t temporary
for filename in filenames:
print '%4d, %s' %(win32file.getfileattributesw(filename), filename)
4. 与运算(&)更直观判断隐藏文件
示例代码如下,& 运算的结果与隐藏属性值相对应,可以更直观的判断文件类型。
filenames = [r'd:\test',
r'd:\test\$recycle.bin',
r'd:\test\.file_test.py.swp',
r'd:\test\file_test.py']
for filename in filenames:
file_flag = win32file.getfileattributesw(filename)
is_hiden = file_flag & win32con.file_attribute_hidden
is_system = file_flag & win32con.file_attribute_system
print '%4d, %s, %s, %s' %(file_flag, is_hiden, is_system, filename)
运行结果:
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论