From 8a95e635cd56e72a51055cd24d38a1cf505be42c Mon Sep 17 00:00:00 2001 From: toxic-recker <62395124+toxicrecker@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:42:16 +0530 Subject: [PATCH] Added `scan_dir` function This is a helper function for implementing a progress indication in the moving games between disks functionality --- legendary/utils/cli.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/legendary/utils/cli.py b/legendary/utils/cli.py index c0fe14a..bad3a59 100644 --- a/legendary/utils/cli.py +++ b/legendary/utils/cli.py @@ -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