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

# Dateien verwalten

> In diesem Abschnitt findest du Informationen und Beispiele dazu, wie du die zu deiner Anwendung gehörenden Dateien bearbeitest. Lerne, wie du Dateien mit der Client- oder der Application-Klasse auflistest, liest, erstellst und löschst, um die Ressourcen deiner Anwendung effizient zu verwalten.

[Client]: client

[Application]: client#application

Alle folgenden Operationen können entweder über die [Client]-Klasse, die
[Application]-Klasse oder die CLI ausgeführt werden. Nachfolgend findest du Beispiele, wie du jede
dieser Aufgaben mit beiden Klassen durchführst:

## Liste der Dateien abrufen

`client.app_files_list` und `app.files_list` geben eine Liste von `FileInfo`-Objekten zurück.

<Tabs>
  <Tab title="Über den Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        files_list = await client.app_files_list(app_id='application_id', path='/')

        for file in files_list:
            print(file.name)  # 'main.py'
            print(file.type)  # 'directory' or 'file'
            print(file.size)  # 2140
            print(file.lastModified)  # 1677112835000
    ```
  </Tab>

  <Tab title="Über die Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        app = await client.app('application_id')
        files_list = await app.files_list(path='/')  # list[FileInfo(...)]

        for file in files_list:
            print(file.name)  # 'main.py'

            print(file.type)  # 'directory' or 'file'

            print(file.size)  # 2140

            print(file.lastModified)  # 1677112835000
    ```
  </Tab>
</Tabs>

## Eine Datei lesen

`client.read_app_file` und `app.read_file` geben ein `BytesIO`-Objekt zurück.

<Tabs>
  <Tab title="Über den Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        file_bytes = await client.read_app_file(
            app_id='application_id', path='main.py'
        )

        print(file_bytes)  # b'01101000 01101001'
    ```
  </Tab>

  <Tab title="Über die Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        app = await client.app('application_id')
        file_bytes = await app.read_file(path='main.py')

        print(file_bytes)  # b'01101000 01101001'
    ```
  </Tab>
</Tabs>

## Eine Datei erstellen

`client.create_app_file` und `app.create_file` geben ein `Response`-Objekt zurück.

<Tabs>
  <Tab title="Über den Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        await client.create_app_file(
            app_id='application_id', path='/file.txt', file=square.File('file.txt')
        )
    ```
  </Tab>

  <Tab title="Über die Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        app = await client.app('application_id')

        await app.create_file(path='/file.txt', file=square.File('file.txt'))
    ```
  </Tab>
</Tabs>

## Eine Datei löschen

`client.delete_app_file` und `app.delete_file` geben ein `Response`-Objekt zurück.

<Tabs>
  <Tab title="Über den Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        await client.delete_app_file(app_id='application_id', path='/file.txt')
    ```
  </Tab>

  <Tab title="Über die Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')

    async def example():
        app = await client.app('application_id')

        await app.delete_file(path='/file.txt')
    ```
  </Tab>
</Tabs>

## Eine Datei verschieben

`client.move_app_file` und `app.move_file` geben ein `Response`-Objekt zurück.

<Tabs>
  <Tab title="Über den Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')


    async def example():
        await client.move_app_file(
            app_id='application_id',
            origin='path/to/origin/file.py',
            dest='path/to/destination/file.py',
        )
    ```
  </Tab>

  <Tab title="Über die Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API KEY')


    async def example():
        app = await client.app('application_id')
        await app.move_file(
            origin='path/to/origin/file.py', dest='path/to/destination/file.py'
        )
    ```
  </Tab>
</Tabs>
