今天爱分享给大家带来Python如何获取一个文件的创建和修改时间【面试题详解】,希望能够帮助到大家。
跨平台的获取文件创建及修改时间的方法
你有很多选择
使用os.path.getmtime或者os.path.getctime
import os.path, time print "last modified: %s" % time.ctime(os.path.getmtime(file)) print "created: %s" % time.ctime(os.path.getctime(file))
或者os.stat
import os, time (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file) print "last modified: %s" % time.ctime(mtime)
注意,ctime()并非指*nix系统中文件创建时间,而是这个节点数据的最后修改时间
原文链接:https://itblood.website/4398.html,转载请注明出处。

![夏之音。辣妹、宅男,秘密的放学后。AI汉化版+存档+去码补丁[新汉化][1.4G] [热门精品SLG/汉化/动态]](/wp-content/uploads/replace/2025/09/09/f16cc11ad1c67d8c04e61d6a97e73b7f.webp)