Maverick
Maverick

Reputation: 107

The time functions time.getmtime and time.getctime gives the same result

Below is a program I wrote to determine the folder creation and last modified time of the folder. But both gives the same result. Can you please suggest what change is required to get the required result?

import os
import time

t1 = os.path.getmtime('folder path')
t2 = os.path.getctime('folder path')
print time.ctime(t1)
print time.ctime(t2)

Upvotes: 0

Views: 1685

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 149145

On Posix system, modification time is the time where the data was last modified, creation time is the time where the file status was last modified.

For example, if you change access rights or rename the file, its creation time will change but not its modification time. So as the opposite of the c would suggest, ctime is generally more recent than mtime.

Here is what man page from stat says:

 st_atim      Time when file data last accessed.  Changed by the mknod(2),
              utimes(2), read(2) and readv(2) system calls.

 st_mtim      Time when file data last modified.  Changed by the mkdir(2),
              mkfifo(2), mknod(2), utimes(2), write(2) and writev(2) sys-
              tem calls.

 st_ctim      Time when file status was last changed (inode data modifica-
              tion).  Changed by the chflags(2), chmod(2), chown(2),
              creat(2), link(2), mkdir(2), mkfifo(2), mknod(2), rename(2),
              rmdir(2), symlink(2), truncate(2), unlink(2), utimes(2),
              write(2) and writev(2) system calls.

Upvotes: 2

Related Questions