GET
/
boxes
/
{boxId}
/
fs
/
list
JavaScript
import GboxSDK, { isFileOperator } 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" });

  const listResult = await box.fs.list({
    path: "/home/user",
    depth: 2
  });

  const files = listResult.filter(isFileOperator);

  for (const file of files) {
    // you can read the file content
    const content = await file.read();
    console.info(`📄 ${file.name} (${file.size}) - ${file.path}`);
    console.info(`content: ${content.data}`);
  }

  // List files in the home directory
  const listInfo = await box.fs.listInfo({
    path: "/home/user",
    depth: 2
  });

  console.log("Files and directories:");
  console.info(JSON.stringify(listInfo, null, 2));
}

main();
{
  "data": [
    {
      "type": "dir",
      "name": "projects",
      "path": "/home/user/documents/projects/",
      "mode": "755",
      "lastModified": "2024-01-15T10:30:00.000Z"
    },
    {
      "type": "file",
      "name": "readme.txt",
      "path": "/home/user/documents/readme.txt",
      "size": "1.2KB",
      "mode": "644",
      "lastModified": "2024-01-15T10:30:00.000Z"
    }
  ]
}

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"

Query Parameters

workingDir
string

Working directory. If not provided, the file will be read from the box.config.workingDir directory.

Example:

"/home/user/documents"

path
string
required

Target directory path in the box

Example:

"/home/user/documents"

depth
number
default:1

Depth of the directory

Example:

2

Response

200
application/json

List files

Response containing directory listing results