Python Forum

Full Version: Finding files matching pattern
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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/