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-18
- 翟天临学术不端事件20192025-04-18
- 海天“双标”争议背后,酱油新国标当有消费者声音2022-10-06
- 世界粮食日来了!我们如何端稳14亿人饭碗?2022-10-16
- 辽宁葫芦岛市部分地区实施静态管理2022-10-12
- 阿拉伯数字转金额大写2024-08-15
- 10年间报考人数翻66倍,“教资热”的背后是什么?2022-10-18
- 中国煤电核准提速 电力人士:今冬明夏用电缺口仍存2022-10-13
- 人民币首次超过美元成为莫斯科交易所交易量最大外币2022-10-05
- 二十大报告亮点纷呈 众多重要表述受关注2022-10-16
