-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir_manipul.py
More file actions
87 lines (63 loc) · 2.48 KB
/
Copy pathdir_manipul.py
File metadata and controls
87 lines (63 loc) · 2.48 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
78
79
80
81
82
83
84
85
86
87
import os
test_pathes = [
'mule\\krolek',
'glue',
'glue\\def\\z2ylc',
'mule',
'mule\\orek'
]
class DirectoryListTool (list):
def __init__(self, *args):
list.__init__(self, *args)
def find_subpathes(self,list_of_pathes):
list_of_subpaths = []
for i in range(0,len(list_of_pathes) - 1):
#print('\r\n')
for j in range (i + 1 ,len(list_of_pathes)):
couplepath = [list_of_pathes[i],list_of_pathes[j]]
cpath = os.path.commonpath(couplepath)
if cpath == couplepath[0]:
list_of_subpaths.append(j)
elif cpath == couplepath[1]:
list_of_subpaths.append(i)
#print('i = {0:#d} j = {1:#d} commonpath = {2}'.format(i,j, cpath))
#print(list_of_subpaths)
return list_of_subpaths
def remove_subpathes(self,list_of_pathes = None):
if list_of_pathes == None:
list_of_pathes = self
list_of_idx_subpaths = self.find_subpathes(list_of_pathes)
list_of_idx_subpaths.sort(reverse = True)
#print(list_of_idx_subpaths)
for i in range(0, len(list_of_idx_subpaths)):
list_of_pathes.pop(list_of_idx_subpaths[i])
def find_dirs_by_name(self, path, dir_name):
self.clear()
for root, dirs, files in os.walk(path):
for name in dirs:
if name == dir_name:
full_path = os.path.join(root, name)
self.append(full_path)
def rename_dirs(self, new_name , list_of_pathes = None):
if list_of_pathes == None:
list_of_pathes = self
for dir_path in list_of_pathes:
new_dir_path = os.path.join(os.path.dirname(dir_path), new_name)
os.rename(dir_path, new_dir_path)
# subpathes_helper = subpathes_opertion()
# print(test_pathes)
# subpathes_helper.remove_subpathes(test_pathes)
# print(test_pathes)
#mouobj = DirectoryListTool(['mule\\krolek',
#'glue',
#'glue\\def\\z2ylc',
#'mule',
#'mule\\orek'])
#mouobj.append('gryj\\jen\\ol')
#mouobj.remove_subpathes()
#print(mouobj)
mouobj = DirectoryListTool()
mouobj.find_dirs_by_name('G:\\Roboczy\\Andrzej_P\\mbed-os\\mbed\\hal\\targets\\hal\\TARGET_NORDIC\\TARGET_NRF5', 'Ssdk')
#print(mouobj)
mouobj.rename_dirs('sdk')
print(mouobj)