Skip to content
Snippets Groups Projects
Commit 33cdd29f authored by imcovangent's avatar imcovangent
Browse files

Added utility function for file size determination.

Former-commit-id: 034561970dae25ae0b9c755129464f1e5fcf9755
parent 1548cb35
No related branches found
No related tags found
No related merge requests found
......@@ -624,3 +624,35 @@ def translate_dict_keys(dictionary, translations):
dictionary[key] = value
return dictionary
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)
else:
raise IOError('Could not find file: {}'.format(file_path))
def file_size_MB(file_path):
"""
this function will return the file size
"""
if os.path.isfile(file_path):
file_info = os.stat(file_path)
return file_info.st_size/1024.0/1024.0
else:
raise IOError('Could not find file: {}'.format(file_path))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment