MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / get_dir_size

Function get_dir_size

archivebox/system.py:144–163  ·  view source on GitHub ↗

get the total disk size of a given directory, optionally summing up recursively and limiting to a given filter list

(path: Union[str, Path], recursive: bool=True, pattern: Optional[str]=None)

Source from the content-addressed store, hash-verified

142
143@enforce_types
144def get_dir_size(path: Union[str, Path], recursive: bool=True, pattern: Optional[str]=None) -> Tuple[int, int, int]:
145 """get the total disk size of a given directory, optionally summing up
146 recursively and limiting to a given filter list
147 """
148 num_bytes, num_dirs, num_files = 0, 0, 0
149 for entry in os.scandir(path):
150 if (pattern is not None) and (pattern not in entry.path):
151 continue
152 if entry.is_dir(follow_symlinks=False):
153 if not recursive:
154 continue
155 num_dirs += 1
156 bytes_inside, dirs_inside, files_inside = get_dir_size(entry.path)
157 num_bytes += bytes_inside
158 num_dirs += dirs_inside
159 num_files += files_inside
160 else:
161 num_bytes += entry.stat(follow_symlinks=False).st_size
162 num_files += 1
163 return num_bytes, num_dirs, num_files
164
165
166CRON_COMMENT = 'archivebox_schedule'

Callers 4

statusFunction · 0.85
calc_dir_sizeMethod · 0.85
archive_sizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected