-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_structure.py
More file actions
44 lines (35 loc) · 1.24 KB
/
create_structure.py
File metadata and controls
44 lines (35 loc) · 1.24 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
37
38
39
40
41
42
43
44
import os
import sys
import json
def create_structure(root_folder, structure):
for key, value in structure.items():
path = os.path.join(root_folder, key)
if isinstance(value, dict):
if not key:
print(f"Error: The key is empty")
sys.exit(1)
os.makedirs(path, exist_ok=True)
create_structure(path, value)
elif isinstance(value, str):
if not key:
print(f"Error: The key is empty")
sys.exit(1)
with open(path, 'w') as file:
file.write(value)
def main():
if len(sys.argv) != 3:
print("Usage: python create_structure.py root_folder_path structure_json_file_path")
sys.exit(1)
root=sys.argv[1]
structure=sys.argv[2]
if not os.path.exists(structure):
print(f"Error: The JSON file '{structure}' does not exist.")
sys.exit(1)
with open(structure, 'r') as json_file:
structure = json.load(json_file)
if not os.path.exists(root):
os.makedirs(root)
create_structure(root, structure)
print("Folder structure created successfully.")
if __name__ == "__main__":
main()