What fields in os.stat()
are filled with dummy values on Windows?
The python doc is not clear on this. In particular, what does st_ino
yield on Windows?
Can somebody run an interactive python session on Windows and let me know? I don't own a Windows machine so I can't do it.
stat() method in Python performs stat() system call on the specified path. This method is used to get status of the specified path.
st_mode This field contains the file type and mode. See inode(7) for further information. st_nlink This field contains the number of hard links to the file. st_uid This field contains the user ID of the owner of the file. st_gid This field contains the ID of the group owner of the file.
st_ino
, st_dev
, st_nlink
, st_uid
, and st_gid
are dummy variables on Windows 7 SP1 through Python 2.7.11:
import os; os.stat('Desktop\test.txt')
nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=293L, st_atime=1448376581L, st_mtime=1451782006L, st_ctime=1448376581L)
However, they appear to be filled with meaningful values in Windows 7 SP1 as of Python 3.5.1:
import os; os.stat('Desktop\test.txt')
os.stat_result(st_mode=33206, st_ino=17732923532870243, st_dev=2289627604, st_nlink=2, st_uid=0, st_gid=0, st_size=293, st_atime=1448376581, st_mtime=1451782006, st_ctime=1448376581)
The Python docs on this topic would lead a sane user to avoid ever using os.stat
in Windows, since there's no guarantee that any field will always/ever be accurate. In practice, it looks like st_size
, st_atime
, st_mtime
, and st_ctime
are usually if not always accurate. The other fields depend on at least the Python version, probably also the Windows version, and possibly other factors.
In Python 3.3.4
>>> os.stat('.')
nt.stat_result(st_mode=16895, st_ino=1407374883604316, st_dev=0, st_nlink=1, st_uid=0,
st_gid=0, st_size=4096, st_atime=1392476826, st_mtime=1392476826, st_ctime=1392374365)
Different from older versions st_ino
is implemented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With