Deleting Files

The zerve's canvas offers different ways to delete a file from file system

Deleting single file

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

Deleting file without code

Deleting multiple files

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

Python syntax for deleting multiple files

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}")
Deleting file using Python

R syntax for deleting multiple blocks

# 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")
}
Deleting files using R

Last updated