from os import listdir all_files = listdir("./path/to/file") csv_files = list(filter(lambda f: f.endswith('.csv'), all_files))
Here is what the above code is Doing:
1. We’re using the os module to get a list of all the files in the directory.
2. We’re using the filter function to filter out all the files that don’t end with .csv.
3. We’re using the list function to convert the filter object into a list.