Skip to main content
Permanently remove files from your workspace to manage storage space and maintain data organization and security.

Delete a File

Remove files from your account:
  • CLI
  • Python SDK
  • JavaScript SDK
Delete by file ID:
gravixlayer files delete 977ca95b-0705-4ad2-846e-7d3d15af3eb2
Delete by filename:
gravixlayer files delete README.md
Example Output (Delete by ID):
🗑️  Deleting file: 977ca95b-0705-4ad2-846e-7d3d15af3eb2
✅ File deleted successfully!
Example Output (Delete by filename):
🗑️  Deleting file: README.md
Looking up file by name...
Found file ID: a804e4a3-ea8b-4ac7-855b-c7977f9d0ed4
✅ File deleted successfully!
Flexible Delete Options: You can delete files using either the file ID or the filename. When using a filename, the CLI will automatically look up the corresponding file ID.

Delete Multiple Files

  • Python SDK
  • JavaScript SDK
import os
from gravixlayer import GravixLayer

client = GravixLayer()

# Delete multiple files by ID
file_ids_to_delete = ["file-abc123", "file-def456", "file-ghi789"]

for file_id in file_ids_to_delete:
    try:
        delete_response = client.files.delete(file_id)
        print(f"✅ Deleted: {delete_response.file_name}")
    except Exception as e:
        print(f"❌ Failed to delete {file_id}: {e}")

# Delete files by purpose
files_response = client.files.list()
temp_files = [f for f in files_response.data if f.purpose == "batch"]

for file in temp_files:
    try:
        delete_response = client.files.delete(file.id)
        print(f"✅ Deleted batch file: {file.filename}")
    except Exception as e:
        print(f"❌ Failed to delete {file.filename}: {e}")

Safe Delete with Confirmation

  • Python SDK
  • JavaScript SDK
import os
from gravixlayer import GravixLayer

client = GravixLayer()

def safe_delete_file(file_id):
    """Delete a file with confirmation"""
    try:
        # Get file info first
        file_info = client.files.retrieve(file_id)
        
        # Show file details
        print(f"File to delete:")
        print(f"  Name: {file_info.filename}")
        print(f"  Size: {file_info.bytes} bytes")
        print(f"  Purpose: {file_info.purpose}")
        print(f"  Created: {file_info.created_at}")
        
        # Ask for confirmation
        confirm = input("Are you sure you want to delete this file? (y/N): ")
        
        if confirm.lower() == 'y':
            delete_response = client.files.delete(file_id)
            print(f"✅ File deleted: {delete_response.file_name}")
            return True
        else:
            print("❌ Deletion cancelled")
            return False
            
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

# Safe delete a file
success = safe_delete_file("your-file-id")

Delete Parameters

ParameterTypeRequiredDescription
file_id_or_namestringYesFile ID (e.g., 977ca95b-0705-4ad2-846e-7d3d15af3eb2) or filename (e.g., README.md)
I