> For the complete documentation index, see [llms.txt](https://yo-sarawut.gitbook.io/snippet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yo-sarawut.gitbook.io/snippet/python/file-handling/check-the-file-size.md).

# Check the File Size

* <https://www.programiz.com/python-programming/examples/check-filesize>

In this example, you will learn to check the file size.

To understand this example, you should have the knowledge of the following [Python programming](https://www.programiz.com/python-programming) topics:

* [Python Directory and Files Management](https://www.programiz.com/python-programming/directory)

### Example 1: Using os module

```python
import os

file_stat = os.stat('my_file.txt')
print(file_stat.st_size)
```

**Output**

```
34
```

The unit of the file size is `byte`.

### Example 2: Using pathlib module

```python
from pathlib import Path

file = Path('my_file.txt')
print(file.stat().st_size)
```

**Output**

```
34
```

The unit of the file size is `byte`.
