Before always used to determine the directory and file recursive method to get all the files in a directory, and later found that Python has been written in this function, do not need to get their own recursion, recording the use of the Os.walk () function
Purpose: get all Files under path and return a list of shapes such as "C:\Program Files\realtek\audio\hda\rtkngui64.exe" []
method:os.walk (path) returns a generator containing (dir,folder,file) three kinds of information (which I do not understand), where file is the file name (RtkNGUI64.exe), Dir is the directory of file, the folder is dir
Record, in short, there is no file, there is a corresponding Dir, folder (multiple) and it corresponds to it (file is lucky haha), so the loop gets the time for the I in file can take the desired data
Code:
1 def getfilelist (Rlist,path) 2 for inch Os.walk (path): 3 for inch File: 4 " %s\%s "%(dir,i)5 rlist.append (t)
Rlist is the result.
Python os.walk () traverse all files in the directory