Advanced Directory Cleanup Tool with Safety Features
dirpurge is a powerful and flexible command-line tool designed to efficiently clean up directories while ensuring safety and user control. With advanced filtering, interactive selection, backup options, and logging, dirpurge offers a robust solution for maintaining a clutter-free system.
Whether you're a developer managing multiple projects or an administrator handling large directory structures, dirpurge helps remove unwanted files and folders quickly and safely.
β Installation
- Run a single command to install
dirpurgeglobally. - Execute the command in PowerShell with administrative privileges.
$downloadUrl = (Invoke-RestMethod -Uri 'https://api.github.com/repos/xsyncio/dirpurge/releases/latest').assets | Where-Object name -like '*dirpurge.exe*' | Select-Object -ExpandProperty browser_download_url
if ($downloadUrl) {
$installPath = 'C:\Program Files\dirpurge'
$exePath = "$installPath\dirpurge.exe"
$batPath = "$installPath\dirpurge.bat"
if (!(Test-Path $installPath)) {
New-Item -Path $installPath -ItemType Directory -Force
}
Invoke-RestMethod -Uri $downloadUrl -OutFile $exePath
Set-Content -Path $batPath -Value "@echo off`r`n`"$exePath`" %*"
$envPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine)
if ($envPath -notlike "*$installPath*") {
[System.Environment]::SetEnvironmentVariable('Path', "$envPath;$installPath", [System.EnvironmentVariableTarget]::Machine)
}
Write-Host "β
dirpurge installed successfully! Restart your terminal to apply changes."
} else {
Write-Host "β Failed to retrieve the download URL. Check the GitHub API response."
}π« Uninstallation
- Run a single command to completely remove
dirpurgeand its associated files. - Execute the command in PowerShell with administrative privileges.
Remove-Item -Path 'C:\Program Files\dirpurge' -Recurse -Force -ErrorAction SilentlyContinue; [System.Environment]::SetEnvironmentVariable('Path', ($([System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) -replace ';?C:\\Program Files\\dirpurge', '')), [System.EnvironmentVariableTarget]::Machine)β Targeted Cleanup - Specify directory names to search and remove.
π« Exclusions - Prevent deletion of specific directories.
π Depth Control - Define how deep the search should go.
π¦ Size Filtering - Remove only directories above a certain size.
π Age Filtering - Delete directories older than a specified number of days.
π Symlink Support - Follow symbolic links during search (optional).
π Safe Deletion - Move files to trash instead of permanently deleting them.
πΎ Backup & Archiving - Automatically create backups or zip archives before deletion.
π± Interactive Mode - Select directories interactively before deletion.
π Confirmation System - Require a specific phrase to confirm deletion.
π Logging & Reporting - Export results to JSON/CSV and log deletion actions.
βοΈ Configurable Settings - Load and save settings using a JSON config file.
π Verbose & Quiet Modes - Adjust output verbosity for better control.
dirpurge [OPTIONS] <path>
<path>(Required) - Base directory to search.
| Option | Alias | Description |
|---|---|---|
-t, --target <target> |
π Specify directory names to search for (multiple allowed). Default: venv .venv node_modules target bin build |
|
-e, --exclude <exclude> |
π« Exclude specific directories from search | |
--depth <depth> |
π Set maximum search depth (0 = unlimited) | |
--min-size <min-size> |
π¦ Minimum directory size in MB to include | |
--min-age <min-age> |
π Minimum age in days to include | |
--follow-symlinks |
π Follow symbolic links | |
--delete |
β Perform deletion | |
-y, --yes |
β Skip confirmation prompts | |
-d, --dry-run |
π΅ Simulate operations without making changes | |
--use-trash |
π Move to trash instead of permanent deletion | |
-b, --backup |
πΎ Create backups before deletion | |
-a, --archive |
π¦ Create zip archives before deletion | |
--backup-dir <DIR> |
π Specify backup/archive directory (default: ./backups) |
|
-i, --interactive |
π± Select directories to delete interactively | |
--confirm-phrase <confirm-phrase> |
π Custom confirmation phrase for deletion (default: DELETE) |
|
--json <FILE> |
π Export results to JSON file | |
--csv <FILE> |
π Export results to CSV file | |
--log <FILE> |
π Write log to file | |
-c, --config <FILE> |
βοΈ Load configuration from a JSON file | |
--save-config <FILE> |
πΎ Save current settings to a config file | |
-v, --verbose |
π Enable verbose output | |
-q, --quiet |
π Suppress non-essential output | |
-h, --help |
π Show help information | |
-V, --version |
π’ Display version |
- Always run with
--dry-runfirst π to verify what will be deleted. - Use
--backupor--archiveπΎ before permanent deletions. - Enable
--interactivemode π± to manually confirm deletions. - Log everything π using
--logfor audit and troubleshooting.
# Basic cleanup in a project directory
$ dirpurge ./project
# Remove only 'node_modules' directories
$ dirpurge ./src -t node_modules --delete
# Load settings from a configuration file
$ dirpurge . --config settings.json
# Interactive mode with safe deletion (move to trash)
$ dirpurge . -i --use-trashInstallation instructions will be added here.
Instead of passing multiple options in the command line, you can use a JSON config file:
{
"target": ["node_modules", "build"],
"exclude": ["dist", "backup"],
"min_size": 50,
"min_age": 30,
"delete": true,
"use_trash": false,
"backup": true,
"backup_dir": "./backups",
"log": "purge.log"
}To use this configuration:
dirpurge ./projects --config settings.jsonTo save the current settings:
dirpurge ./projects --save-config settings.jsonπΉ Improve multi-threaded performance for large-scale cleanup.
πΉ Add a GUI mode for users who prefer a visual interface.
πΉ Implement advanced analytics for better decision-making.
πΉ Provide more granular filtering (e.g., regex-based exclusions).
This project is licensed under the MIT License.
We welcome contributions! Please submit issues and pull requests for feature suggestions, bug fixes, and improvements.
- Fork the repository
- Create a new branch (
feature-xyz) - Commit your changes
- Push to your fork
- Create a pull request
For any questions, bug reports, or feature requests, please open an issue or contact us directly.
Happy purging! π
