Reputation: 305
I am trying to iterate through directory to find folders to change the path. At the moment I am using:
root = tk.Tk(); root.withdraw() # close the tkinter root window
path = filedialog.askdirectory() # open file dialogue box
to select the folder. After being selected a loop is run through that folder and scans all the images within it. However I have a lot of folders to scan through and was wondering if there was a way to scan through a directory and just find the folders so that they could be scanned automatically in python. So that for each folder it changed the path and this looped over all the folders. Any help would be much appreciated.
Upvotes: 0
Views: 98
Reputation: 9132
It sounds like you are looking for os.walk.
os.walk(top, topdown=True, onerror=None, followlinks=False)¶
Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).
Upvotes: 1