-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir_scanner.py
More file actions
36 lines (28 loc) · 1.04 KB
/
Copy pathdir_scanner.py
File metadata and controls
36 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import argparse
import json
def scan_dir(parent_dir, result):
entries = os.listdir(parent_dir)
subdirectories = [entry for entry in entries if os.path.isdir(os.path.join(parent_dir, entry))]
result[os.path.basename(parent_dir)] = subdirectories
for subdir in subdirectories:
scan_dir(os.path.join(parent_dir, subdir), result)
def save_to_json(dir_structure, output_json):
with open(output_json, 'w') as json_file:
json.dump(dir_structure, json_file, indent=2)
def main():
parser = argparse.ArgumentParser(description='PDF Metadata Extraction Script')
parser.add_argument('-d', '--directory', help='Directory to scan for PDF files')
args = parser.parse_args()
if args.directory:
dir = args.directory
else:
dir = os.getcwd()
output_json = 'dir_structure.json'
result = {}
scan_dir(dir, result)
save_to_json(result, output_json)
print(result)
print("\n Scan complete. ",len(result)," directories scanned.")
if __name__ == "__main__":
main()