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