关键词搜索

源码搜索 ×
×

Python文件夹递归读取文件内容

发布2021-08-23浏览605次

详情内容

import json

import requests

import re

import base64

import numpy as np

import os

# 遍历指定目录,显示目python教程录下的所有文件名

def eachFiles(filepath):

    pathDir = os.listdir(filepath)

    for allDir in pathDir:

        child = os.path.join('%s\%s' % (filepath, allDir))

        if os.path.isfile(child):

    #判断文件扩展名是否为"*.req",是则处理,不是则跳过

            if child.endswith(".req"):

                   #读取文件内容

      readFile(child)

            continue

        eachFile(child)

# 遍历出结果 返回文件的名字

def readFile(files):

  #取文件的存放路径,不带文件名

    parent = os.path.dirname(os.path.realpath(files))

    #取文件名,不带文件存放路径

    filenames = os.path.basename(files)

    fopen = open(files, 'r', encoding='utf-8')  # r 代表read

    fileread = fopen.read()

    fopen.close()

if __name__ == "__main__":

    eachFiles(r"D:\project\work\接口测试")

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载