(1)通过os模块的listdir方法
1 from os import listdir 2 from os.path import isfile, join 3 4 files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
(2)通过os模块的walk方法
1 from os import walk 2 3 files = [] 4 for (root, dirnames, filenames) in walk(mypath): 5 files.extend(filenames) 6 break
(3)利用glob模块进行匹配搜索
1 #获取特定类型的文件 2 import glob 3 4 files = glob.glob(mypath + '*.txt')