from multiprocessing import Pool, cpu_count
def get_size_of_folder(folder_path):
Calculate the total size of all files in the given folder.
- folder_path (str): Path to the folder.
- tuple: (folder_path, size in MB)
os.path.getsize(os.path.join(dirpath, f))
for dirpath, _, filenames in os.walk(folder_path)
size_in_mb = total_size / (1024 * 1024)
return folder_path, size_in_mb
def get_folder_sizes(base_path):
Get the sizes of all folders in the given base path.
- base_path (str): Base directory path.
- DataFrame: DataFrame with columns 'Folder' and 'Size (MB)'.
os.path.join(base_path, folder)
for folder in os.listdir(base_path)
if os.path.isdir(os.path.join(base_path, folder))
with Pool(cpu_count()) as p:
sizes = p.map(get_size_of_folder, folders)
df = pd.DataFrame(sizes, columns=['Folder', 'Size (MB)'])