Python Forum
Python: Ignore\Exclude files that contain words - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Python: Ignore\Exclude files that contain words (/thread-40446.html)



Python: Ignore\Exclude files that contain words - Melcu54 - Jul-28-2023

maybe someone needs this information

def save_to_pdf(directory_path):
    modified_files = []
    file_count = 0
    for root, dirs, files in os.walk(directory_path):
        for file_name in files:
            if file_name.endswith(".html"):

                # ignore files that contain 'webinar' in their name
                if "webinar" in file_name:
                    print(f"Fișierul {file_name} conține 'webinar' în numele său și va fi ignorat.")
                    continue

                file_path = root + os.sep + file_name
                file_content = read_text_from_file(file_path)

                # ignore files that contain 'https://pastebin.com' in their content
                if "https://pastebin.com" in file_content:
                    print(f"Fișierul {file_name} conține 'https://pastebin.com' în conținutul său și va fi ignorat.")
                    continue