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

```
