Python OS. Walk (...)

Source: Internet
Author: User

I used to write some Python command line gadgets to simplify some repetitive work in my work. In this case, I had to traverse a directory. I had been writing recursion.ProgramTwo days ago, I discovered that there was a ready-made class library in Python.
This function is OS. Walk (top [, topdown = true [, onerror = none [, followlinks = false]).
Usage:

Import OS <br/> for root, dirs, files in OS. walk ('/opt /'): <br/> Print root # root of the directory currently traversed <br/> Print dirs # all directories under the root of the directory currently traversed <br/> print files # current all files under the root of the directory to be traversed

 

 

 

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.