I'm trying to search a series of folder/subfolders using filters, and then write the results out. It works if results are written to the same array, but can't figure out how to direct matches to specific arrays. Thanks for any suggestions.
matchlist = [ ['*.csv'], ['*.txt'], ['*.jpg'], ['*.png'] ]
filearray = [ [],[],[],[] ]
for root, dirs, files in os.walk(folderpath):
for file in files:
for entry in matchlist:
if file.endswith(entry):
filearray[TheAppropriateSubArray].append(os.path.join(root, file))
Your match list should be:
matchlist = ['.csv', '.txt', '.jpg', '.png']
Then change your:
for entry in matchlist:
if file.endswith(entry):
filearray[TheAppropriateSubArray].append(os.path.join(root, file))
To:
for i, entry in enumerate(matchlist):
if file.endswith(entry):
filearray[i].append(os.path.join(root, file))