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"
}
]
}
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"
}
]
}
Enter your API Key in the format: Bearer <token>. Get it from https://gbox.ai
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Working directory. If not provided, the file will be read from the box.config.workingDir
directory.
"/home/user/documents"
Target directory path in the box
"/home/user/documents"
Depth of the directory
2
List files
Response containing directory listing results
Was this page helpful?