python ctime of a directory referenced by a symbolic link

108 views Asked by At

we have a directory directory and a symlink pointing to it symlink -> directory. Symlink is updated periodically (recreated) but the directory is updated much less often.

Problem: find out what was the directory update time (ctime) using python.

Approach: using os.stat, documentation says it follows symlinks (in python 2).

Debug:

ls -lah symlink    # gives me 8:04
ls -lahd symlink   # gives me 8:04
ls -lahd symlink/  # gives me 6:55
ls -lahd directory # gives me 6:55

6.55 is what i want to get using python os.stat

in python

from stat import S_ISREG, S_ISDIR, S_ISLNK
import os
f = 'symlink/'
st=os.stat(f)
print(S_ISLNK(st.st_mode), S_ISDIR(st.st_mode)

I get False, True (by the way, the same if i run it on f='symlink') That's it it says it's a directory However, st[-1] (which corresponds to st_ctime) will give me an equivalent of 8:04

Question: How to query in python ctime of a directory having a symlink to it?

Thank you

0

There are 0 answers