forked from EdjeElectronics/Image-Dataset-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassswitcher.py
More file actions
29 lines (23 loc) · 790 Bytes
/
classswitcher.py
File metadata and controls
29 lines (23 loc) · 790 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
import os
def switch_first_character(line):
if line.startswith('0'):
return '1' + line[1:]
elif line.startswith('1'):
return '0' + line[1:]
else:
return line
def process_file(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
updated_lines = [switch_first_character(line) for line in lines]
with open(file_path, 'w') as file:
file.writelines(updated_lines)
def main(directory_path):
for filename in os.listdir(directory_path):
if filename.endswith(".txt"):
file_path = os.path.join(directory_path, filename)
process_file(file_path)
print(f"Processed: {filename}")
if __name__ == "__main__":
directory_path = "test/labels"
main(directory_path)