404hub
11/20/2018 - 1:28 PM

Find all files in a directory with specific extension

列出指定目录下特定扩展名的某类文件

import os
if data_path: # data_path is a given directory
    data_filenames = []
    for f in os.listdir(data_path): 
        if f.endswith('.csv'): # list all csv files in the directory
            data_filenames.append(f)
else:
    print('No directory chosen')