Python3 traverse the specified folder and all files and folders

Os module using children:

import os

def get_filelist(dir):
    for home, dirs, files in os.walk(dir):
        print("#######dir list#######")
        for dir in dirs:
            print(dir)
        print("#######dir list#######")

        print("#######file list#######")
        for filename in files:
            print(filename)
            fullname = os.path.join(home, filename)
            print(fullname)
        print("#######file list#######")

if __name__ == "__main__":
    get_filelist('C:\\Python3\\Scripts')

 

Guess you like

Origin www.cnblogs.com/frisk/p/11567175.html