Page 1 of 1

How to get file size

Posted: Wed Jan 08, 2020 5:49 pm
by bradstew
I am using uPython on a STM32F405 using a modified pyboard build. I have a 128Mb SPI external flash connected. i am able to format it for FAT and can read and write files with no problems.

But I cannot get the size of a file on the flash. I have been logging data successfully. It's a large file and I can read the first part of the file using uos.read(1000). The command, os.listdir('/fc') correctly lists all the files on the flash. But I can't figure out how to get the size of the files.

any suggestions?

Re: How to get file size

Posted: Wed Jan 08, 2020 6:16 pm
by Roberthh
os.stat()

Re: How to get file size

Posted: Wed Jan 08, 2020 7:06 pm
by bradstew
Yes, that works. But the numbers returned are not documented.

Re: How to get file size

Posted: Wed Jan 08, 2020 7:25 pm
by Roberthh
They are documented with Python. But you have just to look at the order of the return values. Symbolic names for the fields are not provided.
os.stat(name)[6] is the file size.

Re: How to get file size

Posted: Wed Jan 08, 2020 10:54 pm
by bradstew
Works for me.
Thanks!