Python Program to Check the File Size – 2022

Machine Learning Projects

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

Leave a Comment

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