Created
June 13, 2023 01:23
-
-
Save mark99i/d9427e0f33c29066068063518529ddf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
folders: list[str] = os.listdir('./') | |
folders = list(filter(lambda fldr: not fldr.startswith('.') and os.path.isdir(fldr), folders)) | |
for folder in folders: | |
files: list[str] = os.listdir(folder) | |
files = list(filter(lambda f: f.endswith('.bru'), files)) | |
files = sorted(files) | |
for file in files: | |
pos: int = files.index(file) + 1 | |
content = open(f"{folder}/{file}", 'r', encoding='utf-8').read() | |
old_seq = list(filter(lambda i: " seq: " in i, content.split('\n'))) | |
new_seq = f" seq: {pos}" | |
if len(old_seq) == 0: | |
print(f'WARN: seq not found in {folder}/{file}, skipped') | |
continue | |
content = content.replace(old_seq[0], new_seq, 1) | |
with open(f"{folder}/{file}", 'w', encoding='utf-8') as fd: | |
fd.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment