# file_io | Marsho AI
Kawaii, Intelligent and Easy to Extend

Skip to content

# Module `nonebot_plugin_marshoai.plugins.builtin_tools.file_io` ​

`@on_function_call(description='获取设备上本地文件内容').params(fp=String(description='文件路径')).permission(SUPERUSER)`

### async func `read_file(fp: str) -> str` ​

Description: 获取设备上本地文件内容

Arguments:

> - fp (str): 文件路径

Return: str: 文件内容

Source code or View on GitHub
python

    @on_function_call(description='获取设备上本地文件内容').params(fp=String(description='文件路径')).permission(SUPERUSER)
    async def read_file(fp: str) -> str:
        try:
            async with aiofiles.open(fp, 'r', encoding='utf-8') as f:
                return await f.read()
        except Exception as e:
            return '读取出错: ' + str(e)

`@on_function_call(description='写入内容到设备上本地文件').params(fp=String(description='文件路径'), content=String(description='写入内容')).permission(SUPERUSER)`

### async func `write_file(fp: str, content: str) -> str` ​

Description: 写入内容到设备上本地文件

Arguments:

> - fp (str): 文件路径
> - content (str): 写入内容

Return: str: 写入结果

Source code or View on GitHub
python

    @on_function_call(description='写入内容到设备上本地文件').params(fp=String(description='文件路径'), content=String(description='写入内容')).permission(SUPERUSER)
    async def write_file(fp: str, content: str) -> str:
        try:
            async with aiofiles.open(fp, 'w', encoding='utf-8') as f:
                await f.write(content)
            return '写入成功'
        except Exception as e:
            return '写入出错: ' + str(e)