mayankjoin3

files_not_Containing_ensure_access.py

Jun 26th, 2026
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import os
  2. from datetime import datetime
  3.  
  4. # ---------- CONFIG ----------
  5. ROOT_DIR = r"C:\Users\Mayank\Documents\GitHub\ERP"
  6.  
  7. SEARCH_STRING = "ensure_access("
  8.  
  9. # Ignore these directories (case-insensitive)
  10. IGNORE_DIRS = {"tcpdf", "composer", "phpqrcode", "vendor", "archive", "phpmailer"}
  11.  
  12. timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
  13. OUTPUT_FILE = os.path.join(os.getcwd(), f"text_not_found_{timestamp}.txt")
  14.  
  15. files_not_found = []
  16.  
  17. # ---------- SCAN ----------
  18. for root, dirs, files in os.walk(ROOT_DIR):
  19.     # Skip ignored directories
  20.     dirs[:] = [d for d in dirs if d.lower() not in IGNORE_DIRS]
  21.  
  22.     for file in files:
  23.         if not file.lower().endswith(".php"):
  24.             continue
  25.  
  26.         full_path = os.path.abspath(os.path.join(root, file))
  27.  
  28.         try:
  29.             with open(full_path, "r", encoding="utf-8", errors="ignore") as f:
  30.                 content = f.read()
  31.  
  32.             # If string NOT present
  33.             if SEARCH_STRING not in content:
  34.                 files_not_found.append(full_path)
  35.  
  36.         except Exception as e:
  37.             print(f"Error reading {full_path}: {e}")
  38.  
  39. # ---------- EXPORT ----------
  40. with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
  41.     f.write(f"Search String : {SEARCH_STRING}\n")
  42.     f.write(f"Total PHP files NOT containing string : {len(files_not_found)}\n\n")
  43.  
  44.     for path in sorted(files_not_found):
  45.         f.write(path + "\n")
  46.  
  47. print(f"Total files not containing '{SEARCH_STRING}': {len(files_not_found)}")
  48. print(f"Output written to: {OUTPUT_FILE}")
  49.  
Advertisement
Add Comment
Please, Sign In to add comment