How do Unix filename wildcards work from Python?
A given directory contains only subdirectories, in each of which there is (among others) one file whose name ends with a known string, say _ext
. The first part of the filename always varies, so I need to get to the file by using this pattern.
I wanted to do this:
directory = "."
listofSubDirs = [x[0] for x in os.walk(directory)]
listofSubDirs = listofSubDirs[1:] #removing "."
for subDirectory in listofSubDirs:
fileNameToPickle = subDirectory + "/*_ext" #only one such file exists
fileToPickle = pickle.load(open(fileNameToPickle, "rb"))
... do stuff ...
But no pattern matching happens. How does it work under Python?
Copyright Notice:Content Author:「Ricky Robinson」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15949694/unix-filename-wildcards-in-python