Python os.walk () traverse all files in the directory

Source: Internet
Author: User

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

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.