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.
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:This works because (by default)
os.walk
first lists the files in the requested folder and then goes into subfolders.My a bit more parametrised solution would be this:
Edit: fixes, if/while issue. Thanks, @Dirk van Oosterbosch :}
Well what Kamiccolo meant was more in line with this: