How can I search sub-folders using glob.glob module?

I want to open a series of subfolders in a folder and find some text files and print some lines of the text files. I am using this: configfiles = glob.glob('C:/Users/sam/Desktop/file1/*.txt') But this cannot access the subfolders as well. Does anyone know how I can use the same command to access subfolders as well? Answers: … Read more

Regular expression usage in glob.glob?

import glob list = glob.glob(r'*abc*.txt') + glob.glob(r'*123*.txt') + glob.glob(r'*a1b*.txt') for i in list: print i This code works to list files in the current folder which have ‘abc’, ‘123’ or ‘a1b’ in their names. How would I use one glob to perform this function? Answers: Thank you for visiting the Q&A section on Magenaut. Please … Read more