Python批量打开文件以及获取文件名、目录及路径

 时间:2024-10-21 19:34:00

1、#定义函数,用于打开指定类型文件的函数def open_allfile(path,filetype): data=[] import glob import os read_files=glob.glob(path+'*'+filetype) for i in read_files: with open(i,'rb') as infile: data.append(infile.read()) return datapath指定路径;filetype指定文件类型。

Python批量打开文件以及获取文件名、目录及路径

2、#定义函数用于,获得文件名def get_filename(path,f坡纠课柩iletype): import os 荏鱿胫协name=[] for root,dirs,files in os.walk(path): for i in files: if filetype in i: name.append(i.replace(filetype,'')) return name

Python批量打开文件以及获取文件名、目录及路径

3、#测试path='C:\\Users\\jyjh\\Desktop\\soures\high_CG_pathogen\\'filetype='.txt'data=open_allfile(path,filetype)name=get_filename(path,filetype)name

Python批量打开文件以及获取文件名、目录及路径
  • 如何在Pycharm里面安装pyperclip模块
  • Visio如何绘制IDEE1X数据库表示法
  • MFC如何设置不允许用户关闭EXCEL
  • mysql怎么获取第n条记录
  • echarts在layui中怎么用
  • 热门搜索
    小儿便秘怎么办 腰肌劳损怎么办 玫瑰花怎么叠 晒伤后怎么处理 星星怎么叠 怎么下载游戏 口罩怎么画 消化不好怎么办 衣服上的油渍怎么去除小窍门 银行对账单怎么打印