mavzermete 1
mavzermete
Test5410 1
Test5410
noisiv 1
noisiv
Manwe Work 1
Manwe Work
Reklam vermek için turkmmo@gmail.com

Automat remove define - Grzyb

  • Konuyu başlatan Konuyu başlatan muchomor1337
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 11
  • Görüntüleme Görüntüleme 2K
Thanks for sharing, this version of the code is better.

Disclaimer for c++: if your codes using inner ifdef like this;
C++:
#ifdef __ENABLE_OFFLINE_SHOP
[...]
#ifdef __transmutation
    something
#endif
[...]
#endif
it's gonna delete to the first endif, so it'll occours some errors.

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)
 
Son düzenleme:

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)

Geri
Üst