【Python】Python读取文件夹下的所有文件 您所在的位置:网站首页 Python读取文件内容函数 【Python】Python读取文件夹下的所有文件

【Python】Python读取文件夹下的所有文件

2023-12-28 15:03| 来源: 网络整理| 查看: 265

【Python】Python读取文件夹下的所有文件

你水喝多了: 具体操作参考了下:https://zhuanlan.zhihu.com/p/265694493和博主 感谢二位,代码贴这,用者自取 访问所有文件代码: [code=python] def check_file(path): if not os.path.exists(path): print("File not exist") return False if(os.path.isdir(path)): # 操作文件夹 if not os.access(path, os.R_OK): print("File is accessible to read") return False # todo print(os.path.basename(path)) for file in os.listdir(path): file = os.path.join(path,file) check_file(file) else: # 操作文件 if not os.access(path, os.R_OK): print("File is accessible to read") return False with open(path) as f: # todo print(f.name) [/code]



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有