Python Program to Check the File Size – 2024

Hey guys, in this blog we will see a Python Program to Check the File Size.

Example 1: Using the os module

import os

file_stat = os.stat('img1.jpg')
print(file_stat.st_size)

Output

793103
  • Here we have used os.stat(‘filepath’).st_size to get the size of img1.
  • It tells the size in bytes of a plain file; the amount of data waiting on some special files.

Example 2: Using the pathlib module

from pathlib import Path

file = Path('img1.jpg')
print(file.stat().st_size)

Output

793103

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 517

Leave a Reply

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