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" });
// Rename a file
const renameResult = await box.fs.rename({
oldPath: "/home/user/old_file.txt",
newPath: "/home/user/new_file.txt"
});
console.log("File renamed successfully:", renameResult.message);
// Move and rename a file
const moveResult = await box.fs.rename({
oldPath: "/home/user/document.pdf",
newPath: "/home/user/documents/renamed_document.pdf"
});
console.log("File moved and renamed successfully:", moveResult.message);
}
main();
{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}
Rename a file or dir. If target newPath is already exists, the rename will be failed.
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" });
// Rename a file
const renameResult = await box.fs.rename({
oldPath: "/home/user/old_file.txt",
newPath: "/home/user/new_file.txt"
});
console.log("File renamed successfully:", renameResult.message);
// Move and rename a file
const moveResult = await box.fs.rename({
oldPath: "/home/user/document.pdf",
newPath: "/home/user/documents/renamed_document.pdf"
});
console.log("File moved and renamed successfully:", moveResult.message);
}
main();
{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}
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 renaming a file/directory
Rename file
File system file representation
Was this page helpful?