Python Forum
delete all files which contains word sql_Table1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
delete all files which contains word sql_Table1
#2
Use pathlib:
from pathlib import Path


def remove_files(root, pattern):
    for element in Path(root).rglob(pattern):
        if element.is_file():
            element.unlink()


if __name__ == "__main__":
    tbl = "*sql_Table1*"
    # using the wildcard for rglob()
    folderpath = "E:\\test\reports"
    remove_files(folderpath, tbl)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: delete all files which contains word sql_Table1 - by DeaD_EyE - Sep-15-2022, 01:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help replacing word in Mutiple files. (SOLVED) mm309d 0 917 Mar-21-2023, 03:43 AM
Last Post: mm309d
  python print all files which contain specific word in it mg24 5 1,360 Jan-27-2023, 11:20 AM
Last Post: snippsat
  delete all files and subdirectory from a main folder mg24 7 1,747 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  Delete empty text files [SOLVED] AlphaInc 5 1,665 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  Delete files from amazon s3 bucket python_student 0 4,002 Jan-14-2022, 04:51 PM
Last Post: python_student
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,595 Aug-12-2021, 04:25 PM
Last Post: palladium
  Searching for specific word in text files. JellyCreeper6 1 1,792 Nov-03-2020, 01:52 PM
Last Post: DeaD_EyE
  Complex word search multiple files Kristenl2784 0 1,659 Jul-18-2020, 01:22 PM
Last Post: Kristenl2784
  Python Speech recognition, word by word AceScottie 6 16,182 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 5,015 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020