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" });
// prepare: write a file
await box.fs.write({
path: "/tmp/example.txt",
content: "Hello, world!",
});
// Rename a file
const renamedFile = await box.fs.rename({
oldPath: "/tmp/example.txt",
newPath: "/tmp/example2.txt",
});
console.log("File renamed successfully:", renamedFile.path);
}
main();import os
from gbox_sdk import GboxSDK
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# prepare: write a file
box.fs.write(
path="/tmp/example.txt",
content="Hello, world!"
)
# Rename a file
renamed_file = box.fs.rename(
old_path="/tmp/example.txt",
new_path="/tmp/example2.txt"
)
print("File renamed successfully:", renamed_file.path)
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/rename \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"oldPath": "/home/user/documents/output.txt",
"newPath": "/home/user/documents/new-name.txt"
}
'{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}Rename box/dir
Renames a file or a directory. If the target newPath already exists, the rename will fail.
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" });
// prepare: write a file
await box.fs.write({
path: "/tmp/example.txt",
content: "Hello, world!",
});
// Rename a file
const renamedFile = await box.fs.rename({
oldPath: "/tmp/example.txt",
newPath: "/tmp/example2.txt",
});
console.log("File renamed successfully:", renamedFile.path);
}
main();import os
from gbox_sdk import GboxSDK
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# prepare: write a file
box.fs.write(
path="/tmp/example.txt",
content="Hello, world!"
)
# Rename a file
renamed_file = box.fs.rename(
old_path="/tmp/example.txt",
new_path="/tmp/example2.txt"
)
print("File renamed successfully:", renamed_file.path)
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/rename \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"oldPath": "/home/user/documents/output.txt",
"newPath": "/home/user/documents/new-name.txt"
}
'{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}Authorizations
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Path Parameters
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Body
Request parameters for renaming a file/directory
Old path in the box. If the path does not start with '/', the file/directory will be renamed relative to the working directory. If the oldPath does not exist, the rename will fail.
"/home/user/documents/output.txt"
New path in the box. If the path does not start with '/', the file/directory will be renamed relative to the working directory. If the newPath already exists, the rename will fail.
"/home/user/documents/new-name.txt"
Working directory. If not provided, the file will be read from the box.config.workingDir directory.
"/home/user/documents"
Response
Rename file
- File
- Directory
File system file representation
File type indicator
file Name of the file
"example.txt"
Full path to the file in the box
"/path/to/example.txt"
Size of the file
"10MB"
File metadata
"755"
Last modified time of the file
"2021-01-01T00:00:00Z"
Was this page helpful?