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_STRING = "ensure_access("
- # Ignore these directories (case-insensitive)
- IGNORE_DIRS = {"tcpdf", "composer", "phpqrcode", "vendor", "archive", "phpmailer"}
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
- OUTPUT_FILE = os.path.join(os.getcwd(), f"text_not_found_{timestamp}.txt")
- files_not_found = []
- # ---------- SCAN ----------
- for root, dirs, files in os.walk(ROOT_DIR):
- # Skip ignored directories
- dirs[:] = [d for d in dirs if d.lower() not in IGNORE_DIRS]
- 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()
- # If string NOT present
- if SEARCH_STRING not in content:
- files_not_found.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"Search String : {SEARCH_STRING}\n")
- f.write(f"Total PHP files NOT containing string : {len(files_not_found)}\n\n")
- for path in sorted(files_not_found):
- f.write(path + "\n")
- print(f"Total files not containing '{SEARCH_STRING}': {len(files_not_found)}")
- print(f"Output written to: {OUTPUT_FILE}")
Advertisement
Add Comment
Please, Sign In to add comment