kralhakan2009 1
kralhakan2009
Vahsi Uzman 1
Vahsi Uzman
Cancan.1234 1
Cancan.1234
Hikaye Ekle

Hızlı Source Temizleme (Otomatik Define Silme)

  • Konuyu başlatan Konuyu başlatan Mehmetcan Y.k
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 43
  • Görüntüleme Görüntüleme 13K
3.00 yıldız(lar) 1 Değerlendirme Değerlendirenler
Ekli dosyayı görüntüle 109759

Der Link ist eine Py-Datei, vt ist sowieso nicht nötig, jeder kann ihn scannen.



Die gewünschte Definition wird automatisch gelöscht.

Sie können die folgenden Schritte ausführen, um die Python-Datei auszuführen:

  1. Wenn Python nicht installiert ist, müssen Sie zuerst Python herunterladen und auf Ihrem Computer installieren. Sie können die neueste Version von Python von der offiziellen Python-Website herunterladen:
  2. Sofern eine Terminal- oder Eingabeaufforderung vorliegt. Verwenden Sie den Befehl cd, um in das Verzeichnis zu wechseln, in dem sich die Datei befindet. Beispiel:
    CD-Pfad/zum/Verzeichnis
  3. Verwenden Sie abschließend den folgenden Befehl im Terminal, um die Python-Datei auszuführen:
    python define_sil.py
  4. Das Programm fordert Sie auf, den Ordnerpfad und den zu löschenden Ordner einzugeben. Nach Eingabe der angeforderten Informationen wird der Vorgang gestartet und die Ergebnisse werden auf dem Bildschirm ausgedruckt.


Oder klicken Sie mit der rechten Maustaste auf die Py-Datei und führen Sie sie aus, wählen Sie dort Python aus und öffnen Sie es



Update 0.1


[CODE lang="python" title="My Version"]import os
import shutil
import logging
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

def process_file(file_path, target_define):
"""
Processes a single file to find and remove #ifdef blocks containing the target define.
"""
try:
if not file_path.endswith(('.h', '.cpp', '.hpp', '.c')): # Supported file types
return

# Create a backup of the original file
backup_path = file_path + ".bak"
shutil.copy2(file_path, backup_path)

# Read the file content
with open(file_path, 'r') as f:
lines = f.readlines()

new_content = []
delete_mode = False
ifdef_counter = 0

for line in lines:
if target_define in line: # Found the target define
delete_mode = True

if delete_mode:
if line.strip().startswith(("#ifdef", "#ifndef")):
ifdef_counter += 1
elif line.strip().startswith("#endif"):
ifdef_counter -= 1
if ifdef_counter == 0:
delete_mode = False
continue

if not delete_mode:
new_content.append(line)

# Write the updated content back to the file
with open(file_path, 'w') as f:
f.writelines(new_content)

logging.info(f"Processed file: {file_path}")
except Exception as e:
logging.error(f"Error processing {file_path}: {e}")

def find_and_remove(folder_path, target_define):
"""
Recursively searches a folder for files, identifies #ifdef blocks with the target define, and removes them.
"""
with ThreadPoolExecutor(max_workers=4) as executor:
for folder, _, files in os.walk(folder_path):
for file in tqdm(files, desc=f"Processing {folder}"):
file_path = os.path.join(folder, file)
executor.submit(process_file, file_path, target_define)

if __name__ == "__main__":
folder_path = input("Please enter the folder path: ")
target_define = input("Please enter the define to be removed: ")
find_and_remove(folder_path, target_define)[/CODE]

Features of the Improved Script

1. Supports backups: Ensures the original files are preserved for safety.


2. Processes nested blocks: Correctly handles deeply nested #ifdef blocks.


3. Parallel processing: Speeds up execution by using multithreading (ThreadPoolExecutor).


4. Progress bar: Uses tqdm to provide a progress bar for better user experience.


5. Error handling: Logs errors if files cannot be read or written.
 

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

Geri
Üst