import os def searchWithName(dir,filename,slist=[]): for lists in os.listdir(dir): path = os.path.join(dir,lists) if os.path.isfile(path): dirc,fileNm = os.path.split(path) if fileNm == filename: slist.append(dirc+"\"+fileNm) if os.path.isdir(path): searchWithName(path,filename,slist) return slist