-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
41 lines (32 loc) · 1.38 KB
/
script.py
File metadata and controls
41 lines (32 loc) · 1.38 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
# Script to create directories and python files, from txt file.
# directories need to be marked "folders" at the beginning
# python file will be created in the last scanned directory
import os
# Function to format the directory or file name
def format_name(name):
name = name.replace(':', '').replace('.', '')
return '-'.join(word.capitalize() for word in name.split())
# Open the file
with open('filesFolders.txt', 'r') as f:
lines = f.readlines()
# Initialize the current directory to the root directory
current_dir = 'test'
# Iterate over each line in the file
for line in lines:
line = line.strip() # Remove leading/trailing whitespace
# If the line starts with 'folder', it's a directory
if line.lower().startswith('folder'):
# Remove 'folder' from the directory name
line = line.replace('folder ', '')
# Create the directory under the root directory
current_dir = os.path.join('test', format_name(line))
os.makedirs(current_dir, exist_ok=True)
else:
# Skip files that contain 'Quiz'
if 'Quiz' in line:
continue
# Remove 'Programming exercise: ' from the file name
line = line.replace('Programming exercise: ', '')
# Create a Python file in the current directory
with open(os.path.join(current_dir, f"{format_name(line)}.py"), 'w') as f:
pass