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