> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gbox.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Check if file/dir exists



## OpenAPI

````yaml post /boxes/{boxId}/fs/exists
openapi: 3.0.0
info:
  title: GBOX Open API
  description: GBOX Open API Documentation
  version: '1.0'
  contact: {}
servers:
  - url: https://gbox.ai/api/v1
    description: Production Server
security: []
tags: []
paths:
  /boxes/{boxId}/fs/exists:
    post:
      tags:
        - File System
      summary: Check if file/dir exists
      operationId: FileSystemController_existsFile
      parameters:
        - name: boxId
          required: true
          in: path
          description: Box ID
          schema:
            example: c9bdc193-b54b-4ddb-a035-5ac0c598d32d
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExistsFile'
      responses:
        '200':
          description: >-
            Checks whether a file or directory exists inside a box. Use this
            endpoint for path validation.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ExistsFileResult'
                  - $ref: '#/components/schemas/NotExistsFileResult'
      security:
        - bearer: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            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();
        - lang: Python
          source: |-
            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()
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/gbox/gbox-sdk-go\"\n)\n\nfunc main() {\n\tgboxSDK := gbox.NewGboxSDK(os.Getenv(\"GBOX_API_KEY\"))\n\n\tbox, err := gboxSDK.Create(context.Background(), gbox.CreateOptions{Type: \"linux\"})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create linux box: %v\", err)\n\t}\n\n\t// prepare: write a file\n\t_, err = box.Fs.Write(context.Background(), &gbox.WriteFileRequest{\n\t\tPath:    \"/tmp/example.txt\",\n\t\tContent: \"Hello, world!\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to write file: %v\", err)\n\t}\n\n\t// example: check if a file/directory exists\n\tfileExistsResult, err := box.Fs.Exists(context.Background(), &gbox.ExistsFileRequest{\n\t\tPath: \"/tmp/example.txt\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to check file existence: %v\", err)\n\t}\n\n\tfmt.Printf(\"File exists: %t\\n\", fileExistsResult.Exists)\n\n\t// example: check if a file/directory does not exist\n\tfileNotExistsResult, err := box.Fs.Exists(context.Background(), &gbox.ExistsFileRequest{\n\t\tPath: \"/tmp/non-existent.txt\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to check file existence: %v\", err)\n\t}\n\n\tfmt.Printf(\"File not exists: %t\\n\", fileNotExistsResult.Exists)\n}"
components:
  schemas:
    ExistsFile:
      type: object
      properties:
        workingDir:
          type: string
          description: >-
            Working directory. If not provided, the file will be read from the
            `box.config.workingDir` directory.
          title: FileSystemBase
          example: /home/user/documents
        path:
          type: string
          description: >-
            Target path in the box. If the path does not start with '/', the
            file/directory will be checked relative to the working directory
          title: ExistsFile
          example: /home/user/documents/output.txt
      title: Exists File/Directory
      description: Request parameters for checking if a file/directory exists
      required:
        - path
    ExistsFileResult:
      type: object
      properties:
        exists:
          type: boolean
          description: Exists
          title: ExistsFileResult
          example: true
        type:
          type: string
          description: Type
          title: ExistsFileResult
          example: file
      title: Exists File/Directory Result
      description: Response after checking if a file/directory exists
      required:
        - exists
        - type
    NotExistsFileResult:
      type: object
      properties:
        exists:
          type: boolean
          description: Exists
          title: NotExistsFileResult
          example: false
      title: Not Exists File/Directory Result
      description: Response after checking if a file/directory not exists
      additionalProperties: false
      required:
        - exists
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http
      description: >-
        Enter your API Key in the format: Bearer <token>. Get it from
        https://gbox.ai

````