Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
directory.py23 linesDownload Raw Back to utils
1import os
2
3
4def get_directory_size(directory: str) -> int:
5    """
6    Calculate the total size of the directory by walking through each file.
7
8    Parameters:
9    directory (str): The path of the directory for which to calculate the size.
10
11    Returns:
12    total_size (int): The total size of the directory in bytes.
13    """
14    total_size = 0
15    for dirpath, _, filenames in os.walk(directory):
16        for f in filenames:
17            fp = os.path.join(dirpath, f)
18            # skip if it is symbolic link
19            if not os.path.islink(fp):
20                total_size += os.path.getsize(fp)
21
22    return total_size
23 
codekingpro/portable-devtools · Team Ai