getting file list using glob in python

liv*_*hak 6 python glob python-3.x

I have a list of csv files in mydir.I want to get the list of file names. however using glob as below is returning an empty list.

import glob

mydir = "C:\Data"

file_list = glob(mydir + "*.csv")
print('file_list {}'.format(file_list))
Run Code Online (Sandbox Code Playgroud)

Gre*_*ell 6

Looks like you just need to include your slash to search in the correct directory.

import glob

mydir = "C:\Data"

file_list = glob.glob(mydir + "/*.csv") # Include slash or it will search in the wrong directory!!
print('file_list {}'.format(file_list))
Run Code Online (Sandbox Code Playgroud)