Python Os.walk () walks out of folders and files in the current directory

Source: Internet
Author: User
The parameters of the Os.walk directory traversal Os.walk are as follows:
Os.walk (Top, Topdown=true, Onerror=none, Followlinks=false)

which
-Top is the directory to traverse.
-Topdown represents whether to traverse from top to bottom or from bottom to top.
-OnError can be used to set the handler function when the error is facilitated (the function takes an instance of OSError as a parameter), and is set to NULL to not be processed.
-Followlinks Indicates whether you want to follow the link in the directory to continue the traversal, note that Os.walk does not log the directory that has been traversed, so it is possible to follow the link traversal to continue the call.

Os.walk returns a tuple of 3 elements that (root, dirs, files) represents the traversed path name, the directory list under that path, and the list of files under that path. Note that directory lists and file lists are not specific paths and require a specific path (the path from root) os.path.join(root,dir) os.path.join(root,dir) .

Python Os.walk () walks out of folders and files in the current directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.