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
上一篇:友谊是一株树
下一篇:纯CSS实现立体纸张折叠动效
- 广东宏远:俱乐部内有密接者 决定延迟出队参赛2022-10-04
- 订单排到过年,中国“过冬神器”走红欧洲2022-10-16
- 海天“双标”争议背后,酱油新国标当有消费者声音2022-10-06
- C919获发适航证,准备起飞的还有万亿元产业链2022-10-03
- 重磅利好之后,国庆楼市“战况”如何?2022-10-09
- 华春莹连发13张图,意味深长2022-10-06
- 插茱萸、吃重阳糕、饮菊花酒,重阳习俗了解一下2022-10-04
- 路边相遇,一个细节导致感染,关联病例已超20例!2022-10-11
- “十一”机票价格五年来最低,国庆后市场怎么走2022-10-07
- 浙江发现全球新物种!2022-10-08