python 查找一个指定目录下特定后缀文件,以及遍历文件下的文件夹查找

it2023-10-21  69

# !/usr/bin/env python # -- coding: utf-8 -- import os path = 'D:/test_data' def get_all_file(root_dir): root_path = root_dir path_list = [] file_list = os.listdir(root_path) for file in file_list: file_path = os.path.join(root_path, file) if os.path.isfile(file_path): path_list.append(file_path.replace('\\','/')) if os.path.isdir(file_path): path_list.extend(get_all_file(file_path)) return path_list # def get file_list = get_all_file(path)
最新回复(0)