# Remove PNG Files Workflow

## Description
This workflow provides a safe and systematic approach to removing all `.png` (Portable Network Graphics) image files from the current working directory. The workflow includes safety measures such as previewing files before deletion and optional backup creation.

## Goal
Remove all `.png` files from the current working directory (CWD) while maintaining control and visibility over the deletion process.

## Prerequisites
- Access to a terminal or command-line interface
- Appropriate file permissions for the target directory
- Basic understanding of command-line operations

## Configuration & Parameters

### Required Parameters
- **Target Directory**: Current working directory (CWD) where the command is executed
- **File Extension**: `.png` (case-sensitive by default)

### Optional Parameters
- **Backup Location**: Path to store backup copies before deletion (recommended for important files)
- **Case Sensitivity**: Whether to include `.PNG`, `.Png`, etc.
- **Dry Run**: Preview files without deleting them first

## Step-by-Step Instructions

### Step 1: Navigate to Target Directory
```bash
cd /path/to/target/directory
```
Ensure you are in the correct directory where you want to remove `.png` files.

### Step 2: List All PNG Files (Preview)
Before deleting, review what will be removed:

**Linux/macOS:**
```bash
ls -lh *.png 2>/dev/null
```

**Windows (PowerShell):**
```powershell
Get-ChildItem -Filter "*.png"
```

**Windows (CMD):**
```cmd
dir *.png
```

### Step 3: Count PNG Files (Optional)
Get a count of files to be deleted:

**Linux/macOS:**
```bash
ls -1 *.png 2>/dev/null | wc -l
```

**Windows (PowerShell):**
```powershell
(Get-ChildItem -Filter "*.png").Count
```

### Step 4: Create Backup (Optional but Recommended)
If files might be needed later:

**Linux/macOS:**
```bash
mkdir -p ./png_backup
cp *.png ./png_backup/ 2>/dev/null
```

**Windows (PowerShell):**
```powershell
New-Item -ItemType Directory -Path ".\png_backup" -Force
Copy-Item "*.png" -Destination ".\png_backup\"
```

### Step 5: Remove PNG Files
Execute the deletion command:

**Linux/macOS:**
```bash
rm *.png
```

**Alternative with confirmation:**
```bash
rm -i *.png
```

**Force removal (use with caution):**
```bash
rm -f *.png
```

**Windows (PowerShell):**
```powershell
Remove-Item "*.png"
```

**With confirmation:**
```powershell
Remove-Item "*.png" -Confirm
```

**Windows (CMD):**
```cmd
del *.png
```

**With confirmation:**
```cmd
del /p *.png
```

### Step 6: Verify Deletion
Confirm that all PNG files have been removed:

**Linux/macOS:**
```bash
ls *.png 2>/dev/null
```
Expected output: "No such file or directory" or no output

**Windows (PowerShell):**
```powershell
Get-ChildItem -Filter "*.png"
```
Expected output: No files listed

## Advanced Options

### Case-Insensitive Deletion
To remove `.png`, `.PNG`, `.Png`, etc.:

**Linux/macOS (bash):**
```bash
shopt -s nocaseglob
rm *.png
shopt -u nocaseglob
```

**Using find command:**
```bash
find . -maxdepth 1 -iname "*.png" -type f -delete
```

**Windows (PowerShell):**
PowerShell is case-insensitive by default, so the standard command works.

### Recursive Deletion (Subdirectories)
To remove PNG files from CWD and all subdirectories:

**Linux/macOS:**
```bash
find . -name "*.png" -type f -delete
```

**With preview:**
```bash
find . -name "*.png" -type f
```

**Windows (PowerShell):**
```powershell
Get-ChildItem -Recurse -Filter "*.png" | Remove-Item
```

### Safe Deletion with Trash/Recycle Bin

**Linux (using trash-cli):**
```bash
# Install: sudo apt install trash-cli
trash *.png
```

**macOS:**
```bash
# Using trash command (may need installation)
trash *.png
```

**Windows (PowerShell with RecycleBin):**
```powershell
Get-ChildItem -Filter "*.png" | ForEach-Object {
    $shell = New-Object -ComObject Shell.Application
    $item = $shell.NameSpace(0).ParseName($_.FullName)
    $item.InvokeVerb("delete")
}
```

## Expected Outputs

### Successful Execution
- **Before**: List shows all `.png` files in directory
- **After**: No `.png` files found in directory
- **Exit Code**: 0 (success)
- **Message**: No error messages or confirmation of deletion

### Possible Warnings/Errors
- **"No such file or directory"**: No PNG files exist in CWD (nothing to delete)
- **"Permission denied"**: Insufficient permissions to delete files
- **"File in use"**: File is currently open/locked by another process

## Safety Checklist

- [ ] Verified current working directory is correct
- [ ] Previewed files to be deleted using `ls` or `dir`
- [ ] Created backup if files might be needed (optional)
- [ ] Confirmed file count matches expectations
- [ ] Have appropriate permissions for deletion
- [ ] Considered using interactive/confirmation mode for first execution

## Rollback/Recovery

### If Files Were Deleted Accidentally
1. **Check backup folder** (if Step 4 was performed)
2. **Check trash/recycle bin** (if safe deletion method was used)
3. **Use file recovery tools** (e.g., TestDisk, PhotoRec, Recuva)
4. **Restore from system backups** (Time Machine, File History, etc.)

## Example Use Case

```bash
# Navigate to project directory
cd ~/projects/my-project

# Preview PNG files
ls -lh *.png
# Output: image1.png, screenshot.png, logo.png (3 files, 2.5 MB total)

# Create backup
mkdir -p ./old_images
cp *.png ./old_images/

# Remove PNG files
rm *.png

# Verify
ls *.png
# Output: ls: *.png: No such file or directory
```

## Notes
- This workflow only affects files in the current directory by default (not subdirectories)
- Hidden PNG files (starting with `.`) may require special handling
- Always double-check the directory before executing deletion commands
- Consider using version control (Git) to track important files before deletion
- For production environments, implement proper backup and logging procedures

## Related Workflows
- Bulk file type conversion
- Directory cleanup automation
- Backup and archive creation
- File organization by type

---

**Created**: 2026-02-11  
**Version**: 1.0  
**Workflow Type**: File Management
