Hi,
On an ESP32 I execute Micropython Code. Since wifi and MQTT error can occur from time to time- I keep an error log saved locally.
I wish to know how can I detect file's size, and delete it if it greater that a certain size ( it will be check from time to time ),
Guy
Detect file size and delete
Re: Detect file size and delete
The uos module provides the required functions.
uos.stat(filename)[6] returns the file size.
uos.remove(filename) deletes a file
For further Information, consult the documentation: http://docs.micropython.org/en/latest/p ... y/uos.html
uos.stat(filename)[6] returns the file size.
uos.remove(filename) deletes a file
For further Information, consult the documentation: http://docs.micropython.org/en/latest/p ... y/uos.html
Re: Detect file size and delete
looking at the docs referred - there is no explanation for result vector of uos.stat(filename).Roberthh wrote: ↑Sat Sep 08, 2018 6:27 pmThe uos module provides the required functions.
uos.stat(filename)[6] returns the file size.
uos.remove(filename) deletes a file
For further Information, consult the documentation: http://docs.micropython.org/en/latest/p ... y/uos.html
Re: Detect file size and delete
These are similar to the standard os.stat() of Python. https://docs.python.org/3/library/os.html#os.stat
The symbolic names are not supported, and most fields are not supported by the file system. The three time stamps are all the same. So actually, if you code res=uos.stat(filename), you get
res[0] is the file type (directory or plain file), directory if (res[0] & 0x4000) != 0
res[6] file size
res[8] modification time
The symbolic names are not supported, and most fields are not supported by the file system. The three time stamps are all the same. So actually, if you code res=uos.stat(filename), you get
res[0] is the file type (directory or plain file), directory if (res[0] & 0x4000) != 0
res[6] file size
res[8] modification time
Re: Detect file size and delete
Is there a creation date as well ?
Re: Detect file size and delete
No. As said, all three time stamps are the same. The file system does not provide more information. And, of course, these time stamps are only reasonable if the time was properly set.
Edit res[7], res[8] and res[9] are these three time stamps.
Edit res[7], res[8] and res[9] are these three time stamps.