重命名用于移动文件、提交生成结果或将临时文件切换为正式文件。
移动或重命名文件
Python 示例:
sandbox.files.write("/tmp/result.tmp", "done\n")
sandbox.files.rename("/tmp/result.tmp", "/tmp/result.txt")TypeScript 示例:
await sandbox.files.write("/tmp/result.tmp", "done\n");
await sandbox.files.rename("/tmp/result.tmp", "/tmp/result.txt");也可以用于移动目录:
Python 示例:
sandbox.files.rename("/tmp/build", "/tmp/build-ready")TypeScript 示例:
await sandbox.files.rename("/tmp/build", "/tmp/build-ready");使用建议
生成重要结果时,可以先写入临时文件,再通过 rename() 切换为正式文件,降低读取方看到半成品的概率。
该文章对您有帮助吗?