Thanks for sharing, this version of the code is better.
Disclaimer for c++: if your codes using inner ifdef like this;
it's gonna delete to the first ifdef, so it'll occours some errors.C++:#ifdef __ENABLE_OFFLINE_SHOP [...] #ifdef __transmutation something #endif [...] #endif
For c++;
Python:import os directory = 'C:/Users/Reached/Desktop/workspace/txt/test' encoding = "UTF-8" definition_to_remove = '#ifdef __ENABLE_OFFLINE_SHOP__' for file in os.scandir(directory): if file.name.endswith(('.cpp', '.h')) and file.is_file(): file_path = file.path with open(file_path, 'r', encoding=encoding) as f: lines = f.readlines() with open(file_path, 'w', encoding=encoding) as f: remove_lines = False for line in lines: if definition_to_remove in line: remove_lines = True if remove_lines: if '#endif' in line: remove_lines = False continue f.write(line)
For python;
Python:import os directory = 'C:/Users/Reached/Desktop/workspace/txt/src' encoding = "UTF-8" target_if = 'if app.ENABLE_OFFLINE_SHOP:' for file in os.scandir(directory): if file.name.endswith('.py') and file.is_file(): file_path = file.path with open(file_path, 'r', encoding=encoding) as f: lines = f.readlines() with open(file_path, 'w', encoding=encoding) as f: in_target_block = False target_indent = 0 for line in lines: indent = len(line) - len(line.lstrip()) if target_if in line: in_target_block = True target_indent = indent elif in_target_block and indent > target_indent: continue else: in_target_block = False f.write(line)

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)
Benzer konular
- Cevaplar
- 1
- Görüntüleme
- 349
- Cevaplar
- 6
- Görüntüleme
- 1K
- Cevaplar
- 19
- Görüntüleme
- 2K
- Cevaplar
- 11
- Görüntüleme
- 415