Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0d3849

Browse files
Directory Builder script added
1 parent 3a962f9 commit b0d3849

File tree

4 files changed

+128
-4
lines changed

4 files changed

+128
-4
lines changed

‎Directory Builder/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Directory Builder (dirbuilder.py)
2+
3+
A Python script designed to quickly create project structures based on a predefined layout. It simplifies the process of setting up directory hierarchies with files and folders. Creating a project structure manually can be time-consuming. This script allows you to automate the process, reading a predefined structure from a file and generating the necessary directories and files in your specified project path.
4+
5+
## Requirements
6+
7+
- Python 3
8+
9+
## Usage
10+
11+
**Project Structure File:**
12+
13+
Edit the `structure.txt` file to define your desired project structure. Each line represents a file or directory path relative to the project root. For example:
14+
15+
```bash
16+
my-app/config/appConfig.js",
17+
my-app/config/database.js",
18+
my-app/controllers/database.js",
19+
my-app/controllers/postController.js",
20+
my-app/middlewares/authentication.js",
21+
my-app/middlewares/authorization.js",
22+
my-app/models/post.js",
23+
my-app/models/user.js",
24+
my-app/package.json",
25+
my-app/public/images",
26+
my-app/public/styles",
27+
my-app/routes/index.js",
28+
my-app/routes/api/users.js",
29+
my-app/routes/api/posts.js",
30+
my-app/routes/web/home.js",
31+
my-app/routes/web/auth.js",
32+
my-app/server.js",
33+
my-app/services",
34+
my-app/utils",
35+
```
36+
37+
In this example, the script creates directories and the nested directories along with empty files.
38+
39+
**Run the Script:**
40+
41+
Replace `PROJECT_PATH` in the script with your desired project directory, then run:
42+
43+
```bash
44+
python dirbuilder.py
45+
```
46+
47+
**Output:**
48+
49+
The script creates the specified project structure at the provided project path.
50+
51+
## Combining with Directory Tree Visualizer
52+
53+
You can use `dirbuilder.py` in conjunction with `dirtree.py` to enhance your experience. Utilize `dirtree.py` to visualize and create a directory hierarchy for any existing project. Then, leverage that structure with `dirbuilder.py` to replicate the same organizational setup.

‎Directory Builder/dirbuilder.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
3+
# Define global constants
4+
PROJECT_PATH = 'E:/my-nodejs-app' # Provide your desired project directory
5+
6+
def create_project_structure(project_path):
7+
# Define the structure or read from the file
8+
# structure = [
9+
# "my-app/config/appConfig.js",
10+
# "my-app/config/database.js",
11+
# "my-app/controllers/database.js",
12+
# "my-app/controllers/postController.js",
13+
# "my-app/middlewares/authentication.js",
14+
# "my-app/middlewares/authorization.js",
15+
# "my-app/models/post.js",
16+
# "my-app/models/user.js",
17+
# "my-app/package.json",
18+
# "my-app/public/images",
19+
# "my-app/public/styles",
20+
# "my-app/routes/index.js",
21+
# "my-app/routes/api/users.js",
22+
# "my-app/routes/api/posts.js",
23+
# "my-app/routes/web/home.js",
24+
# "my-app/routes/web/auth.js",
25+
# "my-app/server.js",
26+
# "my-app/services",
27+
# "my-app/utils",
28+
# ]
29+
# Read the directory structure from a file
30+
with open("structure.txt", "r") as file:
31+
structure = [line.strip() for line in file.readlines()]
32+
33+
# Create directories and files
34+
for item in structure:
35+
item_path = os.path.join(project_path, item)
36+
if "." in item:
37+
# File
38+
os.makedirs(os.path.dirname(item_path), exist_ok=True)
39+
with open(item_path, "w") as file:
40+
pass # Creating an empty file
41+
else:
42+
# Directory
43+
os.makedirs(item_path, exist_ok=True)
44+
45+
print(f"Project structure created at {project_path}")
46+
47+
if __name__ == '__main__':
48+
project_directory = PROJECT_PATH
49+
create_project_structure(project_directory)

‎Directory Builder/structure.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
my-app/
2+
my-app/config/
3+
my-app/config/appConfig.js
4+
my-app/config/database.js
5+
my-app/controllers/
6+
my-app/controllers/database.js
7+
my-app/controllers/postController.js
8+
my-app/middlewares/
9+
my-app/middlewares/authentication.js
10+
my-app/middlewares/authorization.js
11+
my-app/models/
12+
my-app/models/post.js
13+
my-app/models/user.js
14+
my-app/package.json
15+
my-app/public/
16+
my-app/public/images/
17+
my-app/public/styles/
18+
my-app/routes/
19+
my-app/routes/index.js
20+
my-app/routes/api/users.js
21+
my-app/routes/api/posts.js
22+
my-app/routes/web/home.js
23+
my-app/routes/web/auth.js
24+
my-app/server.js
25+
my-app/services/
26+
my-app/utils/

‎Directory Tree Visualizer/dirtree.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import os
22
import argparse
33

4-
# Define global constants
5-
# PROJECT_PATH = 'C:/Users/user/Documents/Python/MyProject' # Replace with the actual path to your project
6-
PROJECT_PATH = 'E:/my-nodejs-app'
7-
84
def simple_tree(dir_path):
95
print(os.path.basename(dir_path) + '/')
106

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /