Skip to content

Windows Recent Documents doesn't seem to work #151

Description

@minus21grams

It always comes up empty (on both Classic and Modern).
I had no other option but to add the following custom cleaner (AI generated) to get the job done:

# Fluent Cleaner Modern - Live Cleaner
# Name: Clean Recent File Shortcuts Only
# Description: Removes .lnk shortcuts in %APPDATA%\Microsoft\Windows\Recent that point to files or are broken.
#              Shortcuts to folders/drives are preserved.
#              Verbose logging of every deletion.

param(
    [switch]$VerboseOutput
)

$recentPath = [Environment]::GetFolderPath("Recent")
$shell = New-Object -ComObject WScript.Shell

$deletedCount = 0
$skippedCount = 0
$errorCount = 0

if (-not (Test-Path -Path $recentPath)) {
    Write-Warning "Recent folder not found: $recentPath"
    exit 1
}

Write-Host "Scanning ONLY: $recentPath"
Write-Host "Filter: *.lnk"
Write-Host ""

Get-ChildItem -Path $recentPath -Filter "*.lnk" -ErrorAction SilentlyContinue | ForEach-Object {
    try {
        $shortcut = $shell.CreateShortcut($_.FullName)
        $targetPath = $shortcut.TargetPath

        # No target -> invalid shortcut -> delete
        if (-not $targetPath) {
            Remove-Item -Path $_.FullName -Force
            $deletedCount++
            if ($VerboseOutput) {
                Write-Host "[DELETED] Invalid shortcut (no target): $($_.Name)"
            }
            return
        }

        if (Test-Path $targetPath) {
            $item = Get-Item $targetPath -ErrorAction SilentlyContinue

            if (-not $item) {
                # Cannot resolve item type -> treat as broken -> delete
                Remove-Item -Path $_.FullName -Force
                $deletedCount++
                if ($VerboseOutput) {
                    Write-Host "[DELETED] Unresolvable target: $($_.Name) -> $targetPath"
                }
                return
            }

            if ($item.PSIsContainer) {
                # Folder/Drive -> skip
                $skippedCount++
                if ($VerboseOutput) {
                    Write-Host "[SKIPPED] Folder/Drive shortcut: $($_.Name) -> $targetPath"
                }
                return
            }

            # It's a file -> delete shortcut
            Remove-Item -Path $_.FullName -Force
            $deletedCount++
            if ($VerboseOutput) {
                Write-Host "[DELETED] File shortcut: $($_.Name) -> $targetPath"
            }
        } else {
            # Broken link (target doesn't exist) -> delete
            Remove-Item -Path $_.FullName -Force
            $deletedCount++
            if ($VerboseOutput) {
                Write-Host "[DELETED] Broken link: $($_.Name) -> $targetPath"
            }
        }
    } catch {
        $errorCount++
        Write-Warning "Error processing $($_.FullName): $($_.Exception.Message)"
    }
}

Write-Host ""
Write-Host "Clean Recent File Shortcuts - Summary:"
Write-Host "  Deleted : $deletedCount"
Write-Host "  Skipped : $skippedCount (folders/drives)"
if ($errorCount -gt 0) {
    Write-Host "  Errors  : $errorCount"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions