Get the file name containing the specified content in the current directory and subdirectories, and print the relative path of the file

import them

def search(a,b):
	for file in os.listdir(a): #Determine 
          whether it is a file if os.path.isfile(os.path.join(a,file)): if b in file:
                   #Split the full path print(file,'=>',os.path.join(a,file).split('\\',1)[1]) else:
               #Iteratively process subdirectories search(os.path.join(a,file),b) if __name__ == '__main__': #Get
    the directory where the current file is located, and the file that needs to be searched search(os.path.dirname(__file__),'testinit')

 The above code can be extended according to the extension to make a tool to quickly search local files. Interested children's shoes can extend together. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324767240&siteId=291194637