import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});
async function main() {
const box = await gboxSDK.create({ type: "linux" });
// Check if a file exists
const fileExistsResult = await box.fs.exists({
path: "/home/user/example.txt"
});
console.log("File exists:", fileExistsResult.exists);
// Check if a directory exists
const dirExistsResult = await box.fs.exists({
path: "/home/user/documents"
});
console.log("Directory exists:", dirExistsResult.exists);
// Conditional file operations based on existence
if (fileExistsResult.exists) {
console.log("File exists, proceeding with read operation...");
const content = await box.fs.read({ path: "/home/user/example.txt" });
console.log("File content length:", content.content.length);
} else {
console.log("File does not exist, creating new file...");
await box.fs.write({
path: "/home/user/example.txt",
content: "New file content"
});
}
}
main();
{
"exists": true,
"type": "file"
}
import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});
async function main() {
const box = await gboxSDK.create({ type: "linux" });
// Check if a file exists
const fileExistsResult = await box.fs.exists({
path: "/home/user/example.txt"
});
console.log("File exists:", fileExistsResult.exists);
// Check if a directory exists
const dirExistsResult = await box.fs.exists({
path: "/home/user/documents"
});
console.log("Directory exists:", dirExistsResult.exists);
// Conditional file operations based on existence
if (fileExistsResult.exists) {
console.log("File exists, proceeding with read operation...");
const content = await box.fs.read({ path: "/home/user/example.txt" });
console.log("File content length:", content.content.length);
} else {
console.log("File does not exist, creating new file...");
await box.fs.write({
path: "/home/user/example.txt",
content: "New file content"
});
}
}
main();
{
"exists": true,
"type": "file"
}
Enter your API Key in the format: Bearer <token>. Get it from https://gbox.ai
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Request parameters for checking if a file/directory exists
Check if file/dir exists
Response after checking if a file/directory exists
Was this page helpful?