python os.walk to certain level [duplicate]
问题 This question already has answers here : Travel directory tree with limited recursion depth (2 answers) Closed 2 years ago . I want to build a program that uses some basic code to read through a folder and tell me how many files are in the folder. Here is how I do that currently: import os folders = ['Y:\\path1', 'Y:\\path2', 'Y:\\path3'] for stuff in folders: for root, dirs, files in os.walk(stuff, topdown=True): print("there are", len(files), "files in", root) This works great until there