Removed the() function in python 3.6 version
()
Function declaration: walk(top,topdown=True,oneerror=None)
1. Parameter top represents the path of the directory tree to be traversed
2. Parameters: Farmer topdown is default to "True", which means that first returns the file under the root directory tree, and then traverses the subdirectory of the directory tree. The value of topdown is "False", which means that first traverse the subdirectory of the directory tree, return the files in the subdirectory, and finally return the files in the root directory.
3. The default value of the parameter oneerror is "None", which means that the errors generated during file traversal are ignored. If it is not empty, a custom function prompts the error message, and an exception will be thrown after the traversal is traversal.
4. The function returns a tuple, which has 3 elements, which represent the 'path name, directory list and file list for each traversal'
() Example:
import os def walk(path): if not (path): return -1 for root,dirs,names in (path): for filename in names: print((root,filename)) #The path and file name connection form a complete pathif __name__=='__main__': path = "C:\\Users\\Administrator\\Desktop\\2017-9-1" walk(path)
Output result:
C:\Users\Administrator\Desktop\2017-9-1\ C:\Users\Administrator\Desktop\2017-9-1\ C:\Users\Administrator\Desktop\2017-9-1\ C:\Users\Administrator\Desktop\2017-9-1\Data acquisition and import quality statistics_2017 C:\Users\Administrator\Desktop\2017-9-1\test1\ C:\Users\Administrator\Desktop\2017-9-1\test2\
The above example of obtaining all files or directories () in python files is all the content I share with you. I hope you can give you a reference and I hope you support me more.