spark: add file_counter.py - count files in directory without subdirectories
This commit is contained in:
1 parent
86d5b27653
commit
0f30f29792
1 file changed
+26
@@ -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)
|
||||
Reference in new issue
Block a user