打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python获取文件基本信息

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)

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
把json格式数据写入到本地文件
将文件映射到内存,像数组一样访问
为什么自己的家用电脑不能像网吧电脑那样流畅运行,利用python脚本清理电脑临时文件让自己的电脑不再卡顿?
Python计算文件创建的天数之os、time、datetime
用python实现复制大量文件
C#获取文件大小
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服