Categories
Python Answers

How to check file size in Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *