Python—获取文件基本信息
2019-07-17 09:18:28
import os
def formatTime(longtime):
'''格式化时间的函数'''
import time
return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(localtime))
def formatByte(number):
'''格式化文件大小的函数'''
for(scale.label) in [(1024*1024*1024,"GB"),(1024*1024,"MB"),(1024,"KB")]:
if number>=scale:
return "%.2f %s" %(number*1.0/scale,lable)
elif number ==1:
return "1字节"
else: #小于1字节
byte = "%.2f" % (number or 0)
return (byte[:-3]) if byte.endswith(".00") else byte) + "字节"
fileinfo = os.stat("mr.png") #获取文件的基本信息
print("文件完整路径:",os.path.abspath("mr.png")) #获取文件的完整路径
#输出文件的基本信息
print("索引号:",fileinfo.st_ino)
print("设备名:",fileinfo.st_dev)
print("文件大小:",formatByte(fileinfo.st_size))
print("最后一次访问时间:",formatTime(fileinfo.st_atime))
print("最后一次修改时间:",fileinfo.st_mtime)
print("最后一次状态变化的时间:",fileinfo.st_ctime)
https://www.cnblogs.com/kzxiaotan/articles/10486525.html
上一篇:友谊是一株树
- 国庆假期加班工资咋算?补休与加班费可否二选一?2022-10-08
- 首次披露!“过于先进、不便展示”的画面来了2022-10-08
- 10月10日甘肃新增55例本土无症状感染者2022-10-11
- 徐灿输掉比赛之后,中国拳击向命运挥拳2022-10-10
- 陈时中喊话马斯克,网友笑了:“你哪位”?2022-10-11
- 侠客岛:美军为啥对一块中国磁铁神经过敏?2022-10-11
- 江西鄱阳湖水域面积正在逐步恢复2022-10-17
- 回归正常的生产生活,我们还需多久?国家卫健委回应2022-10-13
- 提升工作效率2019-09-06
- 10月9日新疆新增本土确诊70例、无症状感染者376例2022-10-10
