I'm looking for a way to do a non-recursive os.walk()
walk, just like os.listdir()
works. But I need to return in the same way the os.walk()
returns. Any idea?
Thank you in advance.
Add a break
after the filenames for loop:
for root, dirs, filenames in os.walk(workdir):
for fileName in filenames:
print (fileName)
break #prevent descending into subfolders
This works because (by default) os.walk
first lists the files in the requested folder and then goes into subfolders.