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: "/tmp",
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.data.name} (${file.data.size}) - ${file.data.path}`);
console.info(`file content: ${content}`);
}
// List files in the home directory
const listInfo = await box.fs.listInfo({
path: "/tmp",
depth: 2,
});
console.log("Files and directories:");
console.info(JSON.stringify(listInfo, null, 2));
}
main();import os
import json
from gbox_sdk import GboxSDK
from gbox_sdk.utils import is_file_operator
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
list_result = box.fs.list(
path="/tmp",
depth=2
)
files = [item for item in list_result if is_file_operator(item)]
for file in files:
# you can read the file content
content = file.read()
print(f"📄 {file.data.name} ({file.data.size}) - {file.data.path}")
print(f"file content: {content}")
# List files in the home directory
list_info = box.fs.list_info(
path="/tmp",
depth=2
)
print("Files and directories:")
print(list_info)
if __name__ == "__main__":
main()curl --request GET \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/list \
--header 'Authorization: Bearer <token>'{
"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"
}
]
}File System
List box files
Lists files and directories in a box. You can specify the directory path and depth, and optionally a working directory. The response includes metadata such as type, size, permissions, and last modified time.
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: "/tmp",
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.data.name} (${file.data.size}) - ${file.data.path}`);
console.info(`file content: ${content}`);
}
// List files in the home directory
const listInfo = await box.fs.listInfo({
path: "/tmp",
depth: 2,
});
console.log("Files and directories:");
console.info(JSON.stringify(listInfo, null, 2));
}
main();import os
import json
from gbox_sdk import GboxSDK
from gbox_sdk.utils import is_file_operator
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
list_result = box.fs.list(
path="/tmp",
depth=2
)
files = [item for item in list_result if is_file_operator(item)]
for file in files:
# you can read the file content
content = file.read()
print(f"📄 {file.data.name} ({file.data.size}) - {file.data.path}")
print(f"file content: {content}")
# List files in the home directory
list_info = box.fs.list_info(
path="/tmp",
depth=2
)
print("Files and directories:")
print(list_info)
if __name__ == "__main__":
main()curl --request GET \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/list \
--header 'Authorization: Bearer <token>'{
"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
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Path Parameters
Box ID
Example:
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Query Parameters
Working directory. If not provided, the file will be read from the box.config.workingDir directory.
Example:
"/home/user/documents"
Target directory path in the box
Example:
"/home/user/documents"
Depth of the directory
Example:
2
Response
List files
Response containing directory listing results
Array of files and directories
File system file representation
- File
- Directory
Show child attributes
Show child attributes
Example:
[
{
"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"
}
]
Was this page helpful?