import os def formatTime(longtime): import time return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(longtime)) 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,label) elif number==1: return "1 字节" else: byte= "%.2f "%(number or 0) return (byte[:-3] if byte.endswith("00") else byte)+"字节" stat = os.stat("1.bmp") print("文件完整路径:",os.path.abspath("1.bmp")) print("设备名:",stat.st_dev) print("文件的大小:",formatByte(stat.st_size)) print("最后一次访问时间",formatTime(stat.st_atime)) print("最后一次修改时间",formatTime(stat.st_mtime)) print("文件的状态变化时间",formatTime(stat.st_ctime))
python-获取文件信息
最新推荐文章于 2024-06-21 14:46:19 发布