python获取文件属性
提供三段代码
1、os模块
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
2、调用win32api和win32con
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
3、win32api下的GetFileVersionInfo
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 (ms), LOWORD (ms), HIWORD (ls), LOWORD (ls)
get_version_number("C:\\Program Files\\7-Zip\\7z.exe")
python获取文件属性的更多相关文章
- 使用shell/python获取hostname/fqdn释疑
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Li ...
- python 获取日期
转载 原文:python 获取日期 作者:m4774411wang python 获取日期我们需要用到time模块,比如time.strftime方法 time.strftime('%Y-%m-% ...
- python获取字母在字母表对应位置的几种方法及性能对比较
python获取字母在字母表对应位置的几种方法及性能对比较 某些情况下要求我们查出字母在字母表中的顺序,A = 1,B = 2 , C = 3, 以此类推,比如这道题目 https://project ...
- python获取文件大小
python获取文件大小 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- import os # 字节bytes转化kb\m\g def formatSiz ...
- python 获取一个列表有多少连续列表
python 获取一个列表有多少连续列表 例如 有列表 [1,2,3] 那么连续列表就是 [1,2],[2,3],[1,2,3] 程序实现如下: 运行结果:
- [python实用代码片段]python获取当前时间的前一天,前一周,前一个月
python获取当前时间的前一天,前一周,前一个月. 实用python的datetime.timedelta方法,避免了有的月份是30和31等不同的情况. 获取前一个月的时间,方法实现:首先datet ...
- Python获取目录、文件的注意事项
Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...
- Python 获取 网卡 MAC 地址
/*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...
- python 获取 mac 地址 的代码
python 获取 mac 地址 的例子,有需要的朋友可以参考下. #!/bin/python import os import re def GetMac(): if os.name == ...
随机推荐
- Python概念-定制自己的数据类型(包装)
包装:python为大家提供了标准数据类型,以及丰富的内置方法,其实在很多场景下我们都需要基于标准数据类型来定制我们自己的数据类型,新增/改写方法,这就用到了我们刚学的继承/派生知识(其他的标准类型均 ...
- c++ ACM常用函数
1 保留小数点后两位 #include <iomanip> cout << setiosflags(ios::fixed) << setprecision(2)&l ...
- 在Linode VPS上搭建最新版Transmission
在Linode VPS上搭建最新版Transmission 2015-09-16 by Hansen 原文链接:http://www.hansendong.me/archives/124.html 以 ...
- meterpreter使用
1.基本命令 background:将meterpreter终端隐藏在后台 sessions:查看已经成功获取的会话,想继续与某会话进行交互使用sessions –i quit:直接关闭当前meter ...
- Mysql 监控性能状态 QPS/TPS【转】
QPS(Query per second) 每秒查询量 TPS(Transaction per second)每秒事务量 这是Mysql的两个重要性能指标,需要经常查看,和Mysql基准测试的结果对比 ...
- marshmallow: 简化Python对象系列化
转载:http://www.thinksaas.cn/topics/0/594/594368.html marshmallow -一个轻量级的库用于将复杂对象转成简单的Python数据类型.或从简单的 ...
- 记录一款Unity VR视频播放器插件的开发
效果图 先上一个效果图: 背景 公司最近在做VR直播平台,VR开发我们用到了Unity,而在Unity中播放视频就需要一款视频插件,我们调研了几个视频插件,记录两个,如下: Unity视频插件调研 网 ...
- AngularJS中ng-class使用方法
转自:https://blog.csdn.net/jumtre/article/details/50802136 其他博文ng-class使用方法:https://blog.csdn.net/sina ...
- matlab随笔
主要是记录一些函数.(博客园的一些操作实在是太不方便了) cat函数:http://blog.sina.com.cn/s/blog_6b7dfd9d0100mnz7.html 联结两个数组 magic ...
- JavaScript数据检测
前言: 随着编程实践的增加,慢慢发现关于数据类型的检测至关重要.我认为程序就是为了处理数据和展示数据.所以,数据的检测对于编程来说也至关重要.因为只有符合我们预期的输入,才可能产生正确的输出.众所周知 ...