Sometimes, we want to check file size in Python
In this article, we’ll look at how to check file size in Python.
How to check file size in Python?
To check file size in Python, we can use the st_size
property.
For instance, we write
from pathlib import Path
size = Path("somefile.txt").stat().st_size
to get the stats for the file with
Path("somefile.txt").stat()
Then we get the size of somefile.txt with the st_size
property in bytes.
Conclusion
To check file size in Python, we can use the st_size
property.