Reputation: 53
I have two files in a folder: with name_E.mat
and name_N.mat
. How can I select them by the last letter+extension?
The following code is what I tried:
filedir = r'C:\Users\320037415\Documents\Depth\Proefpersonen\Sub70'
enterprise = glob.glob(filedir + "/_E.mat")
neolead = glob.glob(filedir + "/_N.mat")
filelist = neolead + enterprise
Upvotes: 2
Views: 567
Reputation: 82765
Using the os
module.
Demo:
import os
filedir = r'C:\Users\320037415\Documents\Depth\Proefpersonen\Sub70'
filelist = [file for file in os.listdir(filedir) if file.endswith(("_E.mat", "_N.mat")) ]
Upvotes: 0
Reputation: 106553
You can use *
as a wildcard for file names:
enterprise = glob.glob(filedir + "/*_E.mat")
neolead = glob.glob(filedir + "/*_N.mat")
Upvotes: 2