-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathidReplacement.py
More file actions
31 lines (26 loc) · 854 Bytes
/
idReplacement.py
File metadata and controls
31 lines (26 loc) · 854 Bytes
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
import os
def replaceId(filePath, old, new):
reading_file = open(filePath, "r")
new_file_content = ""
for line in reading_file:
print(line)
stripped_line = line.strip()
print(stripped_line)
oldId = stripped_line.split(' ')[0]
print(oldId)
if(oldId == old):
newId = new
print(newId)
else:
print((filePath, oldId))
new_line = stripped_line.replace(oldId, newId, 1)
new_file_content += new_line + "\n"
reading_file.close()
writing_file = open(filePath, "w")
writing_file.write(new_file_content)
writing_file.close()
# pass the path of folder
path = r'D:/Mangal/LOGIBRICKS/objects/CALENDER/Images(labels)'
for file in os.listdir(path):
if file.endswith('.txt'):
replaceId(path + '/' + file, "519", "538")