0

what does os.stat(path: str) return?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

what does os.stat(path: str) return?

by bludin on Mon Feb 22, 2021 8:48 am

what does os.stat(path: str) return?

https://circuitpython.readthedocs.io/en ... index.html just says

    os.stat(path: str) → Tuple[int, int, int, int, int, int, int, int, int, int]
    Get the status of a file or directory.

The last three fields in the tuple appear to be timestamps, so I would have assumed that they should correspond to created, modified and accessed times. but when I call the function for "code.py" (on an itsybitsy M4 express CP 6.1.0), I get three identical timestamps that seem to correspond to the access time...

bludin
 
Posts: 41
Joined: Thu Apr 16, 2020 8:57 am

Re: what does os.stat(path: str) return?

by dastels on Mon Feb 22, 2021 12:52 pm

According to the source https://github.com/adafruit/circuitpython/blob/main/shared-module/os/__init__.c:

Code: Select all | TOGGLE FULL SIZE
        t->items[0] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR); // st_mode
        for (int i = 1; i <= 9; ++i) {
            t->items[i] = MP_OBJ_NEW_SMALL_INT(0); // dev, nlink, uid, gid, size, atime, mtime, ctime
        }


That accounts for 9 of the returned values.

Dave

dastels
 
Posts: 5394
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.