NSU , , .
, fnmatch , , glob , . :
os.listdir() fnmatch.fnmatch() ...
, :
import glob
matches = glob.glob("/Users/x/y/*.txt")
, , '/Users/x/y/spam.txt', 'spam.txt', , . os.path.basename , , os.path.join , ... "" "".
Also note that I had to manually insert tags "/Users/x/y/"and "*.txt"a single line, as in the command line. This is good, but if, say, the first of the variables, and not hard-coded into the source code, you have to use os.path.join(basepath, "*.txt"), which is not so nice.
By the way, if you are using Python 3.4 or later, you can get the exact same thing from a higher level pathliblibrary:
import pathlib
matches = list(pathlib.Path("/Users/x/y/").glob("*.txt"))
source
share