# 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/r1IzvRlOb2BTlk3M37Ka" 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}")

```

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")
}

```


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
