递归获取文件


import os

def list_files_recursive(folder_path):
    with os.scandir(folder_path) as entries:
        for entry in entries:
            if entry.is_file():
                # 打印文件路径或进行其他操作
                print(entry.path)
            elif entry.is_dir():
                # 递归调用list_files_recursive处理子文件夹
                list_files_recursive(entry.path)

# 指定根文件夹路径
root_folder = '/path/to/your/root/folder'

# 调用递归函数开始遍历
list_files_recursive(root_folder)

评论
  目录