Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from datetime import datetime
- # ---------- CONFIG ----------
- ROOT_DIR = r"C:\Users\Mayank\Documents\GitHub\ERP"
- SEARCH_STRINGS = [
- "ini_set('display_errors', 1);",
- 'ini_set("display_errors", 1);',
- "ini_set('display_startup_errors', 1);",
- 'ini_set("display_startup_errors", 1);',
- "error_reporting(E_ALL);"
- ]
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
- OUTPUT_FILE = f"php_error_reporting_files_{timestamp}.txt"
- matches = []
- # ---------- SCAN ----------
- for root, _, files in os.walk(ROOT_DIR):
- for file in files:
- if not file.lower().endswith(".php"):
- continue
- full_path = os.path.abspath(os.path.join(root, file))
- try:
- with open(full_path, "r", encoding="utf-8", errors="ignore") as f:
- content = f.read()
- # Match if ANY of the three statements are present
- if any(s in content for s in SEARCH_STRINGS):
- matches.append(full_path)
- except Exception as e:
- print(f"Error reading {full_path}: {e}")
- # ---------- EXPORT ----------
- with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
- f.write(f"Total files found: {len(matches)}\n\n")
- for path in sorted(matches):
- f.write(path + "\n")
- f.write("\n\n================ DELETE COMMANDS ================\n\n")
- for path in sorted(matches):
- f.write(f'del "{path}"\n')
- print(f"\nFound {len(matches)} PHP files.")
- print(f"Output written to: {OUTPUT_FILE}")
Advertisement
Add Comment
Please, Sign In to add comment