import os,os.path,re
def searchFile(pathname,filename):#参数1要搜索的路径,参数2要搜索的文件名,可以是正则表代式
matchedFile =[]
for root,dirs,files in os.walk(pathname):
for file in files:
if re.match(filename,file):
fname = os.path.abspath(os.path.join(root,file))
#print(fname)
matchedFile.append(fname)
return matchedFile
def main():
print(searchFile('G:',r'.+\.zip'))#搜索G盘下所有的zip文件
if __name__=="__main__":
main()