> For the complete documentation index, see [llms.txt](https://docs.zerve.ai/guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zerve.ai/guide/canvas-view/files/deleting-files.md).

# Deleting Files

## Deleting single file

The file can be deleted from the canvas UI using delete file option upon right clicking the file.

<figure><img src="/files/6tc1NB9vzCCYZcH2Z4Mf" alt=""><figcaption><p>Deleting file without code</p></figcaption></figure>

## Deleting multiple files

The multiple blocks can be deleted from the file system through Python or R block

Python syntax for deleting multiple files

```python
import os
import glob

# Specify the directory path
directory_path = "./"  # Replace with your directory path

# Use glob to find all files in the directory
files = glob.glob(os.path.join(directory_path, "*"))  # '*' matches all files

# Loop through the files and delete each one
for file_path in files:
    try:
        os.remove(file_path)
        print(f"Deleted: {file_path}")
    except Exception as e:
        print(f"Failed to delete {file_path}. Reason: {e}")

# Optional: Check if the directory is now empty
remaining_files = os.listdir(directory_path)
if not remaining_files:
    print("The directory is now empty.")
else:
    print(f"Remaining files in the directory: {remaining_files}")

```

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIQKNeqjEeOp9UwUcB9R9%2Fuploads%2FyStsrHQF1IPGeC4iXCkE%2FScreen%20Recording%202025-03-27%20at%206.07.22%E2%80%AFPM.mp4?alt=media&token=da9c487c-d88d-4fc6-96b3-9c055a97ce87>" %}
Deleting file using Python
{% endembed %}

R syntax for deleting multiple blocks

```r
# Specify the directory path
directory_path <- "./"  # Replace with your directory path

# List all files in the directory
files <- list.files(directory_path, full.names = TRUE)

# Loop through the files and delete each one
for (file_path in files) {
  if (file.remove(file_path)) {
    cat("Deleted:", file_path, "\n")
  } else {
    cat("Failed to delete:", file_path, "\n")
  }
}

# Optional: Check if the directory is now empty
remaining_files <- list.files(directory_path)
if (length(remaining_files) == 0) {
  cat("The directory is now empty.\n")
} else {
  cat("Remaining files in the directory:", remaining_files, "\n")
}

```

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIQKNeqjEeOp9UwUcB9R9%2Fuploads%2FPa8zRyPSHy1NSuqjQ7ve%2FScreen%20Recording%202025-03-27%20at%206.11.34%E2%80%AFPM.mp4?alt=media&token=15a9ccd6-306c-4385-8b7c-8922bb776f42>" %}
Deleting files using R
{% endembed %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zerve.ai/guide/canvas-view/files/deleting-files.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
