import uos


def rmdir_recursive(path):
    """Recursively delete a directory and all its contents."""
    try:
        # 列出目录下的所有文件和子目录
        for entry in uos.ilistdir(path):
            full_path = path + '/' + entry[0]
            if entry[1] == 0x4000:  # 目录标志
                # 如果是子目录，递归调用自身
                rmdir_recursive(full_path)
            else:
                # 如果是文件，则直接删除
                # print("Deleting file:", full_path)
                uos.remove(full_path)
        # 删除空的顶级目录
        # print("Deleting directory:", path)
        uos.rmdir(path)
    except OSError as e:
        pass
        # print("Error deleting directory:", path, "Error:", e)


def mkdir_p(path):
    """递归创建目录"""
    try:
        uos.mkdir(path)
    except:
        pass


# 使用函数删除指定目录及其所有内容
rmdir_recursive('/temp')

mkdir_p('other_config')
mkdir_p('mode')
mkdir_p('oled')
mkdir_p('sensor')
mkdir_p('sensor/base_mode')
mkdir_p('sensor/mode')
mkdir_p('sensor/other_sensor')
mkdir_p('temp')
mkdir_p('temp/other_config')
mkdir_p('temp/mode')
mkdir_p('temp/oled')
mkdir_p('temp/sensor')
mkdir_p('temp/sensor/base_mode')
mkdir_p('temp/sensor/mode')
mkdir_p('temp/sensor/other_sensor')
