在python中使用glob获取文件列表 [英] getting file list using glob in python

查看:209
本文介绍了在python中使用glob获取文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mydir中有一个csv文件列表,我想获取文件名列表.但是,如下所述使用glob将返回一个空列表.

I have a list of csv files in mydir.I want to get the list of file names. however using glob as below is returning an empty list.

import glob

mydir = "C:\Data"

file_list = glob(mydir + "*.csv")
print('file_list {}'.format(file_list))

推荐答案

看起来您只需要包括斜杠即可在正确的目录中进行搜索.

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))

这篇关于在python中使用glob获取文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆