From 0f30f297928fbf3f248171e589c2473c9991e8c7 Mon Sep 17 00:00:00 2001 From: spark Date: Wed, 21 Oct 2026 02:18:05 +0000 Subject: [PATCH] spark: add file_counter.py - count files in directory without subdirectories --- wizard-work/spark/file_counter.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 wizard-work/spark/file_counter.py diff --git a/wizard-work/spark/file_counter.py b/wizard-work/spark/file_counter.py new file mode 100644 index 0000000..4a2f0f9 --- /dev/null +++ b/wizard-work/spark/file_counter.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +"""Count files in a directory, excluding subdirectories.""" +import sys +import os + +def count_files(path): + if not os.path.exists(path): + print(f"ERROR: Path does not exist: {path}") + return -1 + if not os.path.isdir(path): + print(f"ERROR: Path is not a directory: {path}") + return -1 + + count = 0 + for entry in os.listdir(path): + full_path = os.path.join(path, entry) + if os.path.isfile(full_path): + count += 1 + + print(f"FILE_COUNT:{count}") + return count + +if __name__ == "__main__": + target = sys.argv[1] if len(sys.argv) > 1 else "/root/.hermes/wizard-outputs/spark" + result = count_files(target) + sys.exit(0 if result >= 0 else 1) \ No newline at end of file