Say I have a list of directories dirs.
dirs = ['C:\\path\\to\\dir1','C:\\path\\to\\dir2','C:\\path\\to\\dir3']
And in each of these directories, there are several excel files I want to get a list of. If I just use glob.glob("*.xls*") this only gives me a list of excel files in my current working directory, but I want to specifically get a list of the excel files in "C:\path\to\dir1", "C:\path\to\dir2" etc.
I have tried
import glob
for direc in dirs:
print(glob.glob(direc + "*.xls*")
>>>[]
but this just produces empty lists.
What am I doing wrong here? How can I get a list of the excel files in each of the directories in dirs?
print(glob.glob(direc + "/*.xls*")os.path.join, so it still works if your directory name ends in a slash or back slash.glob.glob('dir*/*.xls*'). If it works from the command-line, it works in Python.