I wanted to get file's inode in my windows machine, so first I tried os.stat('./filename.txt').st_ino
in my REPL and the output I got was 0L
.
I tried the same for a couple of other files and got the same output.
Then, I tried
os.fstat(open("filename.txt", "r").fileno()).st_ino
and I got a long integer in output. For different files the integer was getting changed. So, I think os.fstat worked for windows while os.stat did not. Can someone explain to me the reason for this behavior and other differences between both?
In Python 2 on Windows, stat
calls GetFileAttributesEx
or FindFirstFile
to get standard file information, including file attributes (e.g. directory, readonly), size, and timestamps. fstat
calls GetFileType
(i.e. character, pipe, disk) and GetFileInformationByHandle
, which provides the standard info plus the file index number (like an inode in some ways, but not really), number of hard links, and volume serial number (unused).
Python 2 is a year away from end of life. I suggest you upgrade to Python 3, which has an improved stat
implementation for Windows and further improvements in development