> ## 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.

# Get file/dir

> Retrieves metadata for a specific file or directory inside a box



## OpenAPI

````yaml get /boxes/{boxId}/fs/info
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/info:
    get:
      tags:
        - File System
      summary: Get file/dir
      description: Retrieves metadata for a specific file or directory inside a box
      operationId: FileSystemController_getFileDirectory
      parameters:
        - name: boxId
          required: true
          in: path
          description: Box ID
          schema:
            example: c9bdc193-b54b-4ddb-a035-5ac0c598d32d
            type: string
        - name: workingDir
          required: false
          in: query
          description: >-
            Working directory. If not provided, the file will be read from the
            `box.config.workingDir` directory.
          schema:
            title: FileSystemBase
            example: /home/user/documents
            type: string
        - name: path
          required: true
          in: query
          description: >-
            Target path in the box. If the path does not start with '/', the
            file/directory will be checked relative to the working directory
          schema:
            title: GetFileDirectory
            example: /home/user/documents/output.txt
            type: string
      responses:
        '200':
          description: Get file/dir
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/File'
                  - $ref: '#/components/schemas/Dir'
        '404':
          description: File/dir not found
      security:
        - bearer: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            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" });
              // prepare: write a file
              await box.fs.write({
                path: "/tmp/example.txt",
                content: "Hello, world!",
              });

              // example: read a file/directory
              const file = await box.fs.get({
                path: "/tmp/example.txt",
              });

              if (isFileOperator(file)) {
                const { content } = await file.read();
                console.info(`📄 ${file.data.name} (${file.data.size}) - ${file.data.path}`);
                console.info(`content: ${content}`);
              } else {
                console.info(`📁 ${file.data.name} - ${file.data.path} is a directory`);
              }
            }

            main();
        - lang: Python
          source: |-
            import os
            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")
                # prepare: write a file
                box.fs.write(
                    path="/tmp/example.txt",
                    content="Hello, world!"
                )

                # example: read a file/directory
                file = box.fs.get(
                    path="/tmp/example.txt"
                )

                if is_file_operator(file):
                    content = file.read()
                    print(f"📄 {file.data.name} ({file.data.size}) - {file.data.path}")
                    print(f"content: {content}")
                else:
                    print(f"📁 {file.data.name} - {file.data.path} is a directory")

            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: read a file/directory\n\tfile, err := box.Fs.Get(context.Background(), &gbox.GetFileRequest{\n\t\tPath: \"/tmp/example.txt\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to get file: %v\", err)\n\t}\n\n\tif gbox.IsFileOperator(file) {\n\t\tcontent, err := file.Read(context.Background())\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"Failed to read file: %v\", err)\n\t\t}\n\t\tfmt.Printf(\"📄 %s (%s) - %s\\n\", file.Data().Name, file.Data().Size, file.Data().Path)\n\t\tfmt.Printf(\"content: %s\\n\", content)\n\t} else {\n\t\tfmt.Printf(\"📁 %s - %s is a directory\\n\", file.Data().Name, file.Data().Path)\n\t}\n}"
components:
  schemas:
    File:
      type: object
      properties:
        type:
          type: string
          enum:
            - file
          description: File type indicator
          title: File
        name:
          type: string
          description: Name of the file
          title: File
          example: example.txt
        path:
          type: string
          description: Full path to the file in the box
          title: File
          example: /path/to/example.txt
        size:
          type: string
          description: Size of the file
          title: File
          example: 10MB
        mode:
          type: string
          description: File metadata
          title: File
          example: '755'
        lastModified:
          format: date-time
          type: string
          description: Last modified time of the file
          title: File
          example: '2021-01-01T00:00:00Z'
      title: File
      description: File system file representation
      required:
        - type
        - name
        - path
        - size
        - mode
        - lastModified
    Dir:
      type: object
      properties:
        type:
          type: string
          enum:
            - dir
          description: Directory type indicator
          title: Dir
        name:
          type: string
          description: Name of the directory
          title: Dir
          example: example
        path:
          type: string
          description: Full path to the directory in the box
          title: Dir
          example: /path/to/example/
        mode:
          type: string
          description: Directory metadata
          title: Dir
          example: '755'
        lastModified:
          format: date-time
          type: string
          description: Last modified time of the directory
          title: Dir
          example: '2021-01-01T00:00:00Z'
      title: Directory
      description: File system directory representation
      required:
        - type
        - name
        - path
        - mode
        - lastModified
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http
      description: >-
        Enter your API Key in the format: Bearer <token>. Get it from
        https://gbox.ai

````