Python Forum
Finding files matching pattern
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding files matching pattern
#1
Hi
From a given folder I want to find all files matching this pattern *Tests.dll
In addition these files must be in a directory called Release
In my directory tree there are also folders called Release.ref that I want to exclude

Im new to Python and dont really know where to start

Any help is really appreciated
Reply
#2
from pathlib import Path


def find_flat(root, pattern):
    results = []
    for path in Path(root).glob(pattern):
        if path.is_file():
            results.append(path)

    return results


files = find_flat(".", "*Tests.dll")
There is a whole tuttorial about pathlib and handling files on RealPython: https://realpython.com/python-pathlib/
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using zipfile module - finding folders not files darter1010 2 282 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,509 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Matching two files based on a spited elements tester_V 5 2,827 May-30-2021, 07:49 PM
Last Post: tester_V
  Matching between two files + using next() gwilliamson11 3 2,153 Jun-19-2020, 04:21 AM
Last Post: gwilliamson11
  How to get full path of specified hidden files matching pattern recursively SriRajesh 4 3,951 Jan-18-2020, 07:12 PM
Last Post: SriRajesh
  Pattern Matching With Regexes SnoopFrogg 3 2,844 May-12-2019, 09:13 PM
Last Post: SnoopFrogg
  Finding files knollfinder 2 60,970 Dec-09-2018, 08:03 AM
Last Post: Gribouillis
  Searching a text file to find words matching a pattern Micael 3 87,958 Nov-07-2017, 08:52 PM
Last Post: Micael

Forum Jump:

User Panel Messages

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