How to get file size

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
bradstew
Posts: 10
Joined: Thu Nov 29, 2018 9:29 pm

How to get file size

Post by bradstew » Wed Jan 08, 2020 5:49 pm

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?

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

Re: How to get file size

Post by Roberthh » Wed Jan 08, 2020 6:16 pm

os.stat()

bradstew
Posts: 10
Joined: Thu Nov 29, 2018 9:29 pm

Re: How to get file size

Post by bradstew » Wed Jan 08, 2020 7:06 pm

Yes, that works. But the numbers returned are not documented.

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

Re: How to get file size

Post by Roberthh » Wed Jan 08, 2020 7:25 pm

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.

bradstew
Posts: 10
Joined: Thu Nov 29, 2018 9:29 pm

Re: How to get file size

Post by bradstew » Wed Jan 08, 2020 10:54 pm

Works for me.
Thanks!

Post Reply