How to find out the file creation date and modification date

Asked 2 years ago, Updated 2 years ago, 50 views

I want to find out the file creation date and revision date on Linux and Windows Is there a way to do it with just one code regardless of the platform?

python file

2022-09-22 22:33

1 Answers

Returns the day the given path was last modified. A os.error occurs if the file does not exist or is inaccessible.

import os.path, time
print "last modified: %s" % time.ctime(os.path.getmtime(file))
print "created: %s" % time.ctime(os.path.getctime(file))

Returns an object that contains the following information about the file:

import os
fileinfo = os.stat(path)
print fileinfo.st_mtime
import os, time
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print "last modified: %s" % time.ctime(time)

However, in Linux/unix systems, ctime() means the time when inode data has changed, not the creation date.


2022-09-22 22:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.