WebExeBuilder Documentation

deleteDirRecursively

Category: Directory Operations

Namespace: web.directory.deleteDirRecursively

Description

Deletes a directory and all its contents including files and subdirectories. Use with caution - this operation cannot be undone.

Syntax

const success = await web.directory.deleteDirRecursively({
    dirPath: 'path/to/directory'
});

Parameters

  • dirPath (required) - Directory path to delete recursively (relative or absolute)

Returns

Promise<boolean> - Returns a promise that resolves with true if the directory and all contents were deleted successfully, false otherwise

Examples

Simple example

// WARNING: This deletes everything in the directory!
const success = await web.directory.deleteDirRecursively({
    dirPath: 'C:\\OldData'
});

if (success) {
    console.log('Directory and all contents deleted');
} else {
    console.log('Failed to delete directory');
}

Clean up temporary files

const tempDir = 'temp_processing';

// Delete temporary directory and all its contents
const success = await web.directory.deleteDirRecursively({
    dirPath: tempDir
});

if (success) {
    console.log('Temporary files cleaned up');
}

Safe deletion with confirmation

const dirPath = 'old_backups';

// Verify directory exists
const exists = await web.directory.dirExists({ dirPath });

if (exists) {
    // In a real app, you might show a confirmation dialog here
    const confirmed = confirm('Delete all files in ' + dirPath + '?');
    
    if (confirmed) {
        const success = await web.directory.deleteDirRecursively({
            dirPath
        });
        console.log(success ? 'Deleted' : 'Failed');
    }
}

Use Cases

  • Clean up temporary directories with all their contents
  • Remove old backup folders
  • Delete cache directories
  • Clean up after batch processing operations

Notes

  • WARNING: This permanently deletes the directory and ALL its contents
  • Cannot be undone - deleted files are not sent to Recycle Bin
  • Use deleteDir() instead if you only want to delete empty directories
  • Returns false if the directory doesn't exist
  • Consider adding user confirmation before calling this function