Python Program to Check the File Size – 2024

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

Table of Contents

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

Leave a Reply

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