import os
def convert_bytes(num):"""this function will convert bytes to MB.... GB... etc"""for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:if num < 1024.0:return "%3.1f %s" % (num, x)num /= 1024.0
def file_size(file_path):"""this function will return the file size"""if os.path.isfile(file_path):file_info = os.stat(file_path)return convert_bytes(file_info.st_size)
# Lets check the file size of MS Paint exe# or you can use any file pathfile_path = r"C:\Windows\System32\mspaint.exe"print file_size(file_path)
#Get file size , print it , process it...#Os.stat will provide the file size in (.st_size) property.#The file size will be shown in bytes.
import os
fsize=os.stat('filepath')print('size:' + fsize.st_size.__str__())
#check if the file size is less than 10 MB
if fsize.st_size < 10000000:process it ....