Find all CSV files in a directory using Python

后端 未结 11 1757
生来不讨喜
生来不讨喜 2020-12-02 17:57

How can I find all files in directory with the extension .csv in python?

11条回答
  •  隐瞒了意图╮
    2020-12-02 18:34

    Please use this tested working code. This function will return a list of all the CSV files with absolute CSV file paths in your specified path.

    import os
    from glob import glob
    
    def get_csv_files(dir_path, ext):
        os.chdir(dir_path)
        return list(map(lambda x: os.path.join(dir_path, x), glob(f'*.{ext}')))
    
    print(get_csv_files("E:\\input\\dir\\path", "csv"))
    

提交回复
热议问题