Python3 is used to find files from a specified path,
This example describes how to use Python3 to find files from a specified path. Share it with you for your reference. The specific implementation method is as follows:
A search path is given here. Based on the requested path and the requested file name, find the first file that meets the requirements.
Import OS def search_file (file_name, search_path, pathsep = OS. pathsep): for path in search_path.split (pathsep): candidate = OS. path. join (path, file_name) if OS. path. isfile (candidate): return OS. path. abspath (candidate) return None search_path = 'd: \ pm 'find_file = search_file ('babyos. img ', search_path) if find_file: print ("File 'babyos. img 'found at % s "% find_file) else: print (" File 'babyos. img 'not found ")
I hope this article will help you with Python3 program design.