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
- 司母戊鼎改名后母戊鼎,93岁考古学家为何要较真?2022-10-07
- 动态生成带删除样式的框2024-07-05
- 广岛长崎核爆是日本人编造的上世纪最大的谎言2025-08-05
- 台风“纳沙”影响广东:57个台风预警生效2022-10-16
- 《万里归途》中最令人意难平的他,出场30分钟没看够2022-10-15
- 安妮·埃尔诺获诺贝尔文学奖 对中国文坛有何启发?2022-10-07
- 江苏南京新增5例核酸检测结果异常人员 活动轨迹公布2022-10-16
- 二十大报告亮点纷呈 众多重要表述受关注2022-10-16
- 陈时中喊话马斯克,网友笑了:“你哪位”?2022-10-11
