Loop through all CSV files in a folder

后端 未结 3 1528
太阳男子
太阳男子 2020-12-13 09:47

I\'m trying to loop through only the csv files in a folder that contains many kinds of files and many folders, I just want it to list all of the .csv files in this folder.

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 10:08

    Use the glob module: http://docs.python.org/2/library/glob.html

    import glob
    path = "path/to/dir/*.csv"
    for fname in glob.glob(path):
        print(fname)
    

提交回复
热议问题