首页 > 学院 > 开发设计 > 正文

获取某目录或文件夹下的所有.xls文件的名称

2019-11-08 03:27:07
字体:
来源:转载
供稿:网友
封装一个类:获取某个目录下的所有".xls"的文件的名称列表import osclass GetFileList(object):     def GetFileList(self,dir):        fileLists=[]        if os.path.isdir(dir):            for s in os.listdir(dir):                if s.find(".xls")>0:                    files=s.split(".xls")                    file=files[0]                      fileLists.append(file)

        return fileLists

打印获取到的列表名称

from GetFile import GetFileListBASE_DIR = "C://"GetFileList=GetFileList()FileList=GetFileList.GetFileList(BASE_DIR)for file in FileList:    PRint file


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表