-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_code
More file actions
78 lines (69 loc) · 2.2 KB
/
python_code
File metadata and controls
78 lines (69 loc) · 2.2 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
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
import re
import os
def creating_folder_paths(source_file_name):
filename = "code_search.txt"
source_code = open(source_file_name, "r")
for line in source_code.readlines():
with open(filename, 'a') as f:
for i in line:
if i == "\\":
i = "/"
f.write(i)
else:
f.write(i)
f.close()
source_code.close()
list = []
f = open(filename, "r")
for line in f.readlines():
x = re.findall("\"C:.+\"", line)
if x != []:
list.append(x)
f.close()
question = "Do you want to make a set of nested folders based on the string: "
possible_reply = "?\n A. Yes\n B. No\n"
syntax_error = "Syntax Error: You did not enter a valid response. Only 'A', 'a', 'B', or 'b' are valid responses."
list_keep = []
for item in list:
answer = input(question + str(item) + possible_reply)
if answer == "A" or answer == "a":
list_keep.append(item)
elif answer == "B" or answer == "b":
continue
else:
print(syntax_error)
list1 = []
for item in list_keep:
str_item = str(item)
x = re.findall("/.+/", str_item)
y = str(x)
z = re.split("/", y)
list1.append(z)
list2 = []
for i in list1:
i = i[1:-1]
list3 = []
for j in i:
if j == '':
continue
else:
list3.append(j)
list2.append(list3)
for i in list_keep:
x = list_keep.index(i)
for j in list2[x]:
y = str(i)
y = y[3:-3]
z = re.split("" + j + ".+", y)
parent_dir = z[0]
path = os.path.join(parent_dir, j)
is_exist = os.path.exists(path)
if is_exist == True:
print("The folder path:" + str(path) + " exists")
continue
elif is_exist == False:
os.mkdir(path)
print("The folder path:" + str(path) + " was created")
# To use the function:
source_file_name = "C:\\folder1\\folder2\\folder3\\folder4\\example.py"
creating_folder_paths(source_file_name)