Get File Size
import os
def get_file_size(filepath: str) -> int:
return os.path.getsize(filepath)
def get_file_size_str(filepath: str) -> str:
size = float(os.path.getsize(filepath))
for unit in ('B', 'KB', 'MB', 'GB', 'TB'):
if size < 1024:
return f'{size:.2f}{unit}'
size /= 1024
return f'{size:.2f}PB'