From fc3ddd47d4b576627946fbd51585d4bae031930f Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Tue, 17 Jan 2023 15:01:32 +0100 Subject: [PATCH] Added .py file for support functions --- extras.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 extras.py diff --git a/extras.py b/extras.py new file mode 100644 index 0000000..07e2f4c --- /dev/null +++ b/extras.py @@ -0,0 +1,11 @@ +import os + +def get_size(file_path, unit='bytes'): + file_size = os.path.getsize(file_path) + exponents_map = {'bytes': 0, 'kb': 1, 'mb': 2, 'gb': 3} + if unit not in exponents_map: + raise ValueError("Must select from \ + ['bytes', 'kb', 'mb', 'gb']") + else: + size = file_size / 1024 ** exponents_map[unit] + return round(size, 1)