# 导入os模块，用于文件系统操作
import os

def list_files(path: str, indent: int = 0) -> None:
    """
    循环迭代遍历目录（非递归），带缩进打印所有文件/文件夹
    :param path: 要遍历的初始路径
    :param indent: 初始缩进值
    """
    # 🔥 核心：用栈存储【(目录路径, 缩进值)】，替代递归的调用栈
    # 栈：后进先出，正好匹配目录的深度优先遍历
    stack = [(path, indent)]
    
    # 循环遍历栈，直到栈为空（所有目录都遍历完）
    while stack:
        # 弹出栈顶的【当前目录路径】和【当前缩进值】
        current_path, current_indent = stack.pop()
        
        # 遍历当前目录下的所有文件/文件夹（for循环核心）
        for item in os.listdir(current_path):
            # 拼接完整路径
            full_path = os.path.join(current_path, item)
            # 按缩进打印名称
            print(" " * current_indent + item)
            
            # 如果是文件夹，就把【子目录路径 + 缩进+1】加入栈，等待后续遍历
            if os.path.isdir(full_path):
                stack.append((full_path, current_indent + 1))

# 调用：遍历当前文件夹
list_files(".")