POST
/
boxes
/
{boxId}
/
fs
/
exists
JavaScript
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"
}

Authorizations

Authorization
string
header
required

Enter your API Key in the format: Bearer <token>. Get it from https://gbox.ai

Path Parameters

boxId
string
required

Box ID

Example:

"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"

Body

application/json

Request parameters for checking if a file/directory exists

Response

200 - application/json

Check if file/dir exists

Response after checking if a file/directory exists