Advertisement
nicuf

Python: Ignore/Exclude files that contain words

Jul 28th, 2023 (edited)
1,492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def save_to_pdf(directory_path):
  2.     modified_files = []
  3.     file_count = 0
  4.     for root, dirs, files in os.walk(directory_path):
  5.         for file_name in files:
  6.             if file_name.endswith(".html"):
  7.  
  8.                 # ignore files that contain 'webinar' in their name
  9.                 if "webinar" in file_name:
  10.                     print(f"Fișierul {file_name} conține 'webinar' în numele său și va fi ignorat.")
  11.                     continue
  12.  
  13.                 file_path = root + os.sep + file_name
  14.                 file_content = read_text_from_file(file_path)
  15.  
  16.                 # ignore files that contain 'https://pastebin.com' in their content
  17.                 if "https://pastebin.com" in file_content:
  18.                     print(f"Fișierul {file_name} conține 'https://pastebin.com' în conținutul său și va fi ignorat.")
  19.                     continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement