Last modified: Jan 10, 2023 By Alexander Williams
Getting file size in python
In this article, we'll know how to get file size in python using the os module
syntax:
os.path.getsize(path)
example:
import os
try :
os.path.getsize('/xx/xx/xx/xx/xx/img/access_bg.jpg')
#if the file does not exist or is inaccessible we'll get err
except OSError :
print("Path does not exists or is inaccessible")
output:
180200 #bytes
Return the size, in bytes,