Spaces:
Running
Running
File size: 819 Bytes
947c08e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import os
import concurrent.futures
def _get_file_size(path):
return os.path.getsize(path)
def _get_size(directory, max_threads):
total_size = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=max_threads) as executor:
futures = []
with os.scandir(directory) as entries:
for entry in entries:
if entry.is_file():
futures.append(executor.submit(_get_file_size, entry.path))
elif entry.is_dir():
futures.append(executor.submit(_get_size, entry.path, max_threads))
for future in concurrent.futures.as_completed(futures):
total_size += future.result()
return total_size
def GetDirectorySize(directory, max_threads=5):
return _get_size(directory, max_threads)
|