-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs-maker.py
111 lines (100 loc) · 2.92 KB
/
fs-maker.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
import tkinter as tk
from tkinter import messagebox, filedialog
import json
example_structure = """{
"name": "project_name",
"files": [
"manage.py"
],
"subdirectories": [
{
"name": "project_name",
"files": [
"__init__.py",
"settings.py",
"urls.py",
"wsgi.py"
],
"subdirectories": [
{
"name": "apps",
"files": [],
"subdirectories": [
{
"name": "app1",
"files": [
"__init__.py",
"models.py",
"views.py"
],
"subdirectories": []
},
{
"name": "app2",
"files": [
"__init__.py",
"models.py",
"views.py"
],
"subdirectories": []
}
]
},
{
"name": "templates",
"files": [],
"subdirectories": []
},
{
"name": "static",
"files": [],
"subdirectories": [
{
"name": "css",
"files": [],
"subdirectories": []
},
{
"name": "js",
"files": [],
"subdirectories": []
}
]
}
]
}
]
}"""
def create_structure():
structure_json = txt.get('1.0', 'end')
root_dir = filedialog.askdirectory(title="Select Root Directory")
if not root_dir:
return
structure = json.loads(structure_json)
create_directory_structure(structure, root_dir)
messagebox.showinfo("Success", "Directory structure created successfully!")
def create_directory_structure(directory, parent_path):
directory_name = directory["name"]
path = os.path.join(parent_path, directory_name)
os.makedirs(path, exist_ok=True)
for file in directory.get("files", []):
file_path = os.path.join(path, file)
open(file_path, 'a').close()
for subdir in directory.get("subdirectories", []):
create_directory_structure(subdir, path)
window = tk.Tk()
window.title("Directory Structure Creator")
window.geometry('800x600')
lbl = tk.Label(window, text="Enter Directory Structure (JSON). " +
"Please ensure that you adhere to the format provided in the example:")
lbl.grid(column=0, row=0, padx=15, pady=5, sticky="W")
txt = tk.Text(window, width=40, height=10)
txt.grid(column=0, row=1, padx=15, pady=5, sticky="nsew")
txt.insert(tk.END, example_structure)
window.grid_columnconfigure(0, weight=1)
window.grid_rowconfigure(0, weight=0)
window.grid_rowconfigure(1, weight=1)
btn_submit = tk.Button(window, text="Create Structure", command=create_structure)
btn_submit.grid(column=0, row=2, padx=15, pady=15, sticky="W")
window.mainloop()