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))
Answer from Green Cell on Stack OverflowGeeksforGeeks
geeksforgeeks.org › python › how-to-use-glob-function-to-find-files-recursively-in-python
How to use Glob() Function to Find Files Recursively in Python - GeeksforGeeks
October 3, 2025 - # Python program to find files # recursively using Python import glob # Returns a list of names in list files. print("Using glob.glob()") files = glob.glob('/home/geeks/Desktop/gfg/**/*.txt', recursive = True) for file in files: print(file) ...
00:23
Easily List Files in Python with Glob (No Hassle!) - YouTube
11:53
Glob Module: File Searching in Python - YouTube
Python and the Glob Function Easy Tutorial
06:26
Python standard library: Directory listings with the "glob" module ...
11:54
Tutorial 27 - Using glob to read multiple files in python - YouTube
13:05
glob in Python (Complete Explanation with Examples) - YouTube
Built In
builtin.com › software-engineering-perspectives › glob-in-python
Glob in Python Explained | Built In
| Video: Python Tutorials for Digital Humanities · Here we have an input folder with several CSV files containing stock data. Let’s use glob to identify the files: import pandas as pd import glob # set search path and glob for files # here we want to look for csv files in the input directory path = 'input' files = glob.glob(path + '/*.csv') # create empty list to store dataframes li = [] # loop through list of files and read each one into a dataframe and append to list for f in files: # read in csv temp_df = pd.read_csv(f) # append df to list li.append(temp_df) print(f'Successfully created dataframe for {f} with shape {temp_df.shape}') # concatenate our list of dataframes into one!
Top answer 1 of 3
12
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))
2 of 3
4
Try fnmatch:
import os
from fnmatch import fnmatch
mydir = "C:/Data"
file_list = [file for file in os.listdir(mydir) if fnmatch(file, '*.csv')]
print('file_list {}'.format(file_list))
Also, use RegEx:
import os
import re
mydir = "C:/Data"
file_list = [file for file in os.listdir(mydir) if re.search('.*\.png', file)]
print('file_list {}'.format(file_list))
By the way, glob is a module, you should use glob.glob() like this:
from glob import glob
mydir = "C:/Data"
file_list = glob(mydir + "/*.csv")
print('file_list {}'.format(file_list))
W3Schools
w3schools.com › python › ref_module_glob.asp
Python glob Module
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... import glob import tempfile import os with tempfile.TemporaryDirectory() as d: open(os.path.join(d, "Emil.txt"), "w").close() open(os.path.join(d, "Linus.txt"), "w").close() open(os.path.join(d, "Tobias.py"), "w").close() hits = glob.glob(os.path.join(d, "*.txt")) print(sorted(os.path.basename(x) for x in hits)) Try it Yourself »
Python Module of the Week
pymotw.com › 2 › glob
glob – Filename pattern matching - Python Module of the Week
If you need a list of filenames that all have a certain extension, prefix, or any common string in the middle, use glob instead of writing code to scan the directory contents yourself.
Real Python
realpython.com › get-all-files-in-directory-python
How to Get a List of All Files in a Directory With Python – Real Python
January 12, 2025 - For a direct list of files and folders, you use .iterdir(). The .glob() and .rglob() methods support glob patterns for filtering files with specific extensions or names. For advanced filtering, you can combine these methods with comprehensions or filter functions. By the end of this tutorial, you’ll understand that you can: List all files of a directory in Python using pathlib.Path().iterdir()
TechBeamers
techbeamers.com › python-list-all-files-directory
Python List All Files in a Directory - TechBeamers
November 30, 2025 - As mentioned above, it has a walk() method which lists all files inside a directory in Python. Besides, it has another function listdir() that finds files on the specified path. Similarly, Python’s Glob module has a glob() method that checks for the specified files in the current directory.
Medium
martinxpn.medium.com › glob-working-with-files-in-python-64-100-days-of-python-31e0916f046e
Glob — Working with Files in Python (64/100 Days of Python) | by Martin Mirakyan | Medium
April 10, 2023 - Glob supports the use of wildcard characters to match files with similar names or extensions. Here are the most commonly used wildcard characters: *: Matches any string of characters, including an empty string. ... For example, let’s say you want to get a list of all files in the my_folder directory that have a .txt extension.
Michael Currin
michaelcurrin.github.io › dev-cheatsheets › cheatsheets › python › files-and-paths › glob.html
Glob | Dev Cheatsheets
glob.glob(pathname, *, recursive=False) Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. pathname · can be either absolute (like /usr/src/Python-1.5/Makefile) or relative (like ../../Tools//.gif), and can contain shell-style wildcards.
Earth Data Science
earthdatascience.org › home
Use the OS and Glob Python Packages to Manipulate File Paths | Earth Data Science - Earth Lab
November 12, 2020 - The glob function can be used to find just one folder or file. This can be done by just giving glob the path of the item you are trying to find. # Get a specific directory file_list = glob(data_folder) file_list
ChristopherGS
christophergs.com › python › 2017 › 01 › 01 › python-glob
Using Python glob
January 1, 2017 - glob.glob(pathname, *, recursive=False) The main guy: Returns a list of pathnames depending on the search criteria passed in with “pathname”
Scaler
scaler.com › home › topics › glob() in python
glob() in Python - Scaler Topics
May 4, 2023 - To produce the arbitrary values for the list of files in the output, the iglob() function of the glob module is quite helpful. With the iglob() method, a Python generator can be produced. To list the files in a given directory, we can utilize the Python generator made by the glob module.