JavaScript
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!",
});
// example: check if a file/directory exists
const fileExistsResult = await box.fs.exists({
path: "/tmp/example.txt",
});
console.log("File exists:", fileExistsResult.exists);
// example: check if a file/directory does not exist
const fileNotExistsResult = await box.fs.exists({
path: "/tmp/non-existent.txt",
});
console.log("File not exists:", fileNotExistsResult.exists);
}
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!"
)
# example: check if a file/directory exists
file_exists_result = box.fs.exists(
path="/tmp/example.txt"
)
print("File exists:", file_exists_result.exists)
# example: check if a file/directory does not exist
file_not_exists_result = box.fs.exists(
path="/tmp/non-existent.txt"
)
print("File not exists:", file_not_exists_result.exists)
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/exists \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "/home/user/documents/output.txt"
}
'{
"exists": true,
"type": "file"
}File System
Check if file/dir exists
POST
/
boxes
/
{boxId}
/
fs
/
exists
JavaScript
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!",
});
// example: check if a file/directory exists
const fileExistsResult = await box.fs.exists({
path: "/tmp/example.txt",
});
console.log("File exists:", fileExistsResult.exists);
// example: check if a file/directory does not exist
const fileNotExistsResult = await box.fs.exists({
path: "/tmp/non-existent.txt",
});
console.log("File not exists:", fileNotExistsResult.exists);
}
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!"
)
# example: check if a file/directory exists
file_exists_result = box.fs.exists(
path="/tmp/example.txt"
)
print("File exists:", file_exists_result.exists)
# example: check if a file/directory does not exist
file_not_exists_result = box.fs.exists(
path="/tmp/non-existent.txt"
)
print("File not exists:", file_not_exists_result.exists)
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/exists \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "/home/user/documents/output.txt"
}
'{
"exists": true,
"type": "file"
}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"
Body
application/json
Request parameters for checking if a file/directory exists
Target path in the box. If the path does not start with '/', the file/directory will be checked relative to the working directory
Example:
"/home/user/documents/output.txt"
Working directory. If not provided, the file will be read from the box.config.workingDir directory.
Example:
"/home/user/documents"
Response
200 - application/json
Checks whether a file or directory exists inside a box. Use this endpoint for path validation.
Was this page helpful?