1 #!/usr/bin/python 2 #coding=UTF-8 3 #FileName:search.py 4 #文件搜索 5 import os; 6 import sys; 7 returnList = []; 8 def search_file_in_dir(fileName, dirName): 9 global returnList;10 #print dirName;11 if not os.path.isdir(dirName):12 sys.exit('directory does not exist.(%s)'%(dirName));13 fileList = [x for x in os.listdir(dirName) if os.path.isfile(os.path.join(dirName,x))];14 #print fileList;15 dirList = [i for i in os.listdir(dirName) if os.path.isdir(os.path.join(dirName,i))];16 #print dirList;17 if fileName in fileList:18 returnList.append(os.path.join(dirName, fileName));19 20 dirListLen = len(dirList);21 if dirListLen > 0:22 for d in dirList:23 search_file_in_dir(fileName, os.path.join(dirName, d));24 return returnList;25 26 print search_file_in_dir(sys.argv[1], sys.argv[2]);