Search the file name including the specified word and extension in the directory

Searches for files in the specified directory that contain the specified word and extension. Don't forget to include a dot (.) In the extension when calling the function.

def check_file(path='./',file_name='',ext=''):
    import os
    import os.path

    _ch = os.listdir(path)
    ch_e = []

    for _ in _ch:
        _root, _ext = os.path.splitext(_)
        if file_name in _root and _ext == ext:
            ch_e.append(_)
        else:
            pass

    return ch_e

ch = check_file(path,'name','.txt')

Recommended Posts

Search the file name including the specified word and extension in the directory
Extract only the file name excluding the directory in the directory
Recursively search the specified directory to see the file
Replace the directory name and the file name in the directory together with a Linux command.
Format the Git log and get the committed file name in csv format
Search for files with the specified extension
[Python] Read the specified line in the file
The file name was bad in Python and I was addicted to import
I want to get the file name, line number, and function name in Python 3.4
How to list files under the specified directory in a list (multiple conditions / subdirectory search)
Read the csv file and display it in the browser
Python> library> os> os.walk ()> Get directory structure / Implementation to get each file path in the specified directory
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
Save the pystan model and results in a pickle file
[Python] Open the csv file in the folder specified by pandas
Print the name of the object directly under the object specified in Blender
Get the MIME type in Python and determine the file format
Get the file name saved in AWS S3 (1000 or more)
Search for variables in pandas.DataFrame and get the corresponding row.
[Note] Import of a file in the parent directory in Python
Google search for the last line of the file in Python
Download the file in Python
File access under the directory
Linux file and directory permissions
About the need for the first slash in the subscriber name and publisher name
Save the Pydrive authentication file in a different directory from the script
Get the list in the S3 bucket with Python and search with a specific Key. Output the Key name, last update date, and count number to a file.
Dig the directory and create a list of directory paths + file names
Save the binary file in Python
The story of the "hole" in the file
[Linux] File and directory operation commands
Understand Cog and Extension in discord.py
Get the host name in Python
Judge the extension and download the image
The one that divides the csv file, reads it, and processes it in parallel
Test & Debug Tips: Create a file of the specified size in Python
View the full path (absolute path) of a file in a directory in Linux Bash
Open an Excel file in Python and color the map of Japan
A command to specify a file with a specific name in a directory with find and mv, cp, or gzip it (linux)