Check Paths
Updated at:
Checking whether a path exists is useful as a pre-check before writing, reading, or running commands.
Check whether a file exists
Python example:
exists = sandbox.files.exists("/tmp/result.json")
if not exists:
sandbox.files.write("/tmp/result.json", "{}")TypeScript example:
const exists = await sandbox.files.exists("/tmp/result.json");
if (!exists) {
await sandbox.files.write("/tmp/result.json", "{}");
}Get path information
Python example:
info = sandbox.files.get_info("/tmp/result.json")
print(info.name)
print(info.type)
print(info.path)TypeScript example:
const info = await sandbox.files.getInfo("/tmp/result.json");
console.log(info.name);
console.log(info.type);
console.log(info.path);Recommendations
exists() only tells you whether the path existed at the moment of the check. Concurrent tasks may modify files afterward, so critical writes still need idempotency and error handling on the application side.
Is this page helpful?