what are the fields in os.stat

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

what are the fields in os.stat

Post by rhubarbdog » Sun Sep 23, 2018 8:51 am

os.stat returns a tuple what does each number represent?
i'm guessing the 7 element `os.stat()[6]` is the number of bytes the file takes up.
How could i have researched this myself i couldn't find any `os.c` or `os.py` file at https://github.com/micropython/micropython/

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: what are the fields in os.stat

Post by Roberthh » Sun Sep 23, 2018 10:07 am

The tuple follows the python standard, explained e.g. here:
https://www.tutorialspoint.com/python3/os_stat.htm
But due to the limitation of the FAT file system, only a few members have reasonable value.
os.stat()[0] tells the file type, regular or directory.
os.stat()[6] is the file size
os.stat()[7], os.stat()[8], os.stat()[9] are all the same and tell the modification time. For that value to be correct, the time has to be set.
The place where this is implemented is micropython/extmod/vfs_fat.c, line 293ff

tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

Re: what are the fields in os.stat

Post by tecdroid » Thu Dec 09, 2021 4:15 pm

btw. why isn't this put into a tiny class like fsstatvs? I mean, this shouldn't be that much effort and makes uos a little more like python os..

Post Reply