I have a folder filled with thousands of .ai files. The way this folder is arranged is it initially has subfolders titled with a customer's name, and within each of those subfolders is a unique directory of some or many subfolders that contain .ai's, or subfolders within subfolders within subs... that contain .ai's, or no subfolders just .ai files.
I need a program that will iterate through this folder by taking every .ai filename inside of a customer subfolder(regardless of how many subfolders, or subs within subs, etc...) and append it to a list. Then I'll take that list and do some ocr stuff to it later, but once that's done I'll clear the list and move on to the next subfolder.
This is the code I used to attempt this but it failed. It returns an empty list sometimes, or a list with just one filename in it, when it should return a list each time with one or multiple .ai filenames inside of it.
def folder_loop(folder):
temp_list = []
for root, dirs, files in os.walk(folder):
for dir in dirs:
for file in dir:
if file.endswith("ai"):
temp_list.append(os.path.join(root, file))
print(temp_list)
temp_list.clear()
I'm a begginer and I hardly understand what the code is even doing so I'm not surprised it didn't work. Any ideas?