Added scan_dir function

This is a helper function for implementing a progress indication in the moving games between disks functionality
This commit is contained in:
toxic-recker 2023-01-09 21:42:16 +05:30 committed by GitHub
parent b30e274251
commit 8a95e635cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,5 @@
import os
def get_boolean_choice(prompt, default=True):
yn = 'Y/n' if default else 'y/N'
@ -89,3 +91,15 @@ def strtobool(val):
else:
raise ValueError("invalid truth value %r" % (val,))
def scan_dir(src):
files = 0
chunks = 0
for entry in os.scandir(src):
if entry.is_dir():
cnt, sz = scan_dir(entry.path)
files += cnt
chunks += sz
else:
files += 1
chunks += entry.stat().st_size
return files, chunks