deleteFile
Category: File Operations
Namespace: web.files.deleteFile
Description
Deletes a file from the file system. This operation cannot be undone.
Syntax
const success = await web.files.deleteFile({
filePath: 'path/to/file.txt'
});
Parameters
- filePath (required) - Path to the file to delete (relative or absolute)
Returns
Promise<boolean> - Returns a promise that resolves with true if the file was deleted successfully, false otherwise
Examples
Simple example
const success = await web.files.deleteFile({
filePath: 'temp.txt'
});
if (success) {
console.log('File deleted successfully');
} else {
console.log('Failed to delete file');
}
Clean up temporary files
const tempFiles = ['temp1.txt', 'temp2.txt', 'cache.dat'];
for (const file of tempFiles) {
const success = await web.files.deleteFile({ filePath: file });
console.log(`${file}: ${success ? 'deleted' : 'failed'}`);
}
Safe deletion with confirmation
const filePath = 'important_data.txt';
// Verify file exists first
const exists = await web.files.fileExists({ filePath });
if (exists) {
const confirmed = confirm('Delete ' + filePath + '?');
if (confirmed) {
await web.files.deleteFile({ filePath });
}
}
Use Cases
- Clean up temporary files
- Remove old log files
- Delete user-requested files
- Clear cache files
- Remove outdated data files
Notes
- WARNING: Deletion is permanent and cannot be undone
- Files are not sent to the Recycle Bin
- Returns
falseif the file doesn't exist - Returns
falseif the file is locked or in use - Consider adding user confirmation for important files