Open your Downloads folder at the end of the year and you may find years of PDFs, installers and ZIP files. Deleting everything feels risky, but checking each file by hand takes forever.
So I wrote a small PowerShell tool for it. It lists the files you have not changed in a set number of days, lets you check the list, and then moves them into a single ZIP. You pick the number of days in a window, and you can also include folders with names like “old” or “archive”. The originals go to the Recycle Bin only after the tool has found them inside the ZIP.

Ways to clean up old files on Windows
Windows gives you a few ways to deal with old files. They differ mainly in whether the files are deleted or kept, and whether you get to see a list before anything happens.
| Method | What it does | Downside |
|---|---|---|
| Sort by date in File Explorer | You pick files by hand and move them yourself | Hard to cover subfolders. Easy to miss files when there are many |
| Storage Sense (Windows Settings) | Deletes files in Downloads that you have not opened for a set number of days | It only deletes. Nothing is kept |
| robocopy with /MOV and /MINAGE | Moves files older than a set number of days to another place | No list to review first, and no ZIP |
| PowerShell (the tool in this post) | Shows a list first, puts the checked files into a ZIP, and sends the originals to the Recycle Bin | You need to extract the ZIP to open a file |
For files you probably do not need but are not ready to delete, a ZIP is a good middle ground. It is one file, so it fits easily on an external drive or a NAS, and you can still pull a file out later.
I use it for year-end cleanup of Downloads and the desktop. It also helps with shared work folders where people keep piling files into folders named “old” or “archive”.
Before you run it: risks and safeguards
The tool moves files, so a few things can go wrong.
- A template you open once a year can look old by date, so you may move a file you still use
- Shortcuts or Excel links that point to a moved file will stop working
- Files on a NAS or mapped network drive skip the Recycle Bin and are simply deleted
That is why listing files changes nothing, and files you uncheck stay where they are. When it moves files, the tool reopens the ZIP and only touches files it finds there with the same name and size. Even then, the originals go to the Recycle Bin rather than being deleted. Still, the first time you use it, or when you use it on a NAS folder, copy the folder first and try it on the copy.
The script
Open PowerShell (5.1 or 7 both work), paste the whole script and press Enter. The window opens. You do not need to run it as administrator. If you save it as a .ps1 file, save it as UTF-8 with BOM.
# ===== Starting values (you can change them in the window every time) =====
$defaultFolder = Join-Path $env:USERPROFILE "Downloads" # Folder to clean up
$defaultDays = 90 # Files last changed more than this many days ago
$defaultKeywords = "old,archive" # Folder name words: everything inside is included (comma separated)
# ============================================================================
Add-Type -AssemblyName System.Windows.Forms, System.Drawing, Microsoft.VisualBasic
Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem
[System.Windows.Forms.Application]::EnableVisualStyles()
function Add-Ctl($ctl, $x, $y, $w, $h) {
$ctl.Location = New-Object System.Drawing.Point($x, $y)
$ctl.Size = New-Object System.Drawing.Size($w, $h)
$form.Controls.Add($ctl)
return $ctl
}
function Pick-Folder($box) {
$dlg = New-Object System.Windows.Forms.FolderBrowserDialog
if (Test-Path -LiteralPath $box.Text) { $dlg.SelectedPath = $box.Text }
if ($dlg.ShowDialog() -eq "OK") { $box.Text = $dlg.SelectedPath }
}
function Get-DestPath {
if ($txtDest.Text.Trim()) { return $txtDest.Text.Trim().TrimEnd("\") }
return (Join-Path $txtFolder.Text.Trim().TrimEnd("\") "_zip-archive")
}
function Update-Total {
$n = 0; $size = 0
foreach ($row in $grid.Rows) {
if ($row.Cells[0].Value) { $n++; $size += $row.Tag.Length }
}
$lblTotal.Text = "{0} files / {1:N1} MB selected (unchecked files stay where they are)" -f $n, ($size / 1MB)
$btnMove.Enabled = ($n -gt 0)
}
$form = New-Object System.Windows.Forms.Form
$form.Text = "Archive old files to a ZIP"
$form.Size = New-Object System.Drawing.Size(900, 640)
$form.StartPosition = "CenterScreen"
$form.Font = New-Object System.Drawing.Font("Segoe UI", 9)
$lbl = Add-Ctl (New-Object System.Windows.Forms.Label) 12 15 120 20; $lbl.Text = "Folder to clean"
$txtFolder = Add-Ctl (New-Object System.Windows.Forms.TextBox) 135 12 640 23; $txtFolder.Text = $defaultFolder
$btnFolder = Add-Ctl (New-Object System.Windows.Forms.Button) 785 11 80 25; $btnFolder.Text = "Browse..."
$btnFolder.Add_Click({ Pick-Folder $txtFolder })
$lbl = Add-Ctl (New-Object System.Windows.Forms.Label) 12 47 120 20; $lbl.Text = "Days"
$numDays = Add-Ctl (New-Object System.Windows.Forms.NumericUpDown) 135 44 70 23
$numDays.Minimum = 0; $numDays.Maximum = 3650; $numDays.Value = $defaultDays
$lblDays = Add-Ctl (New-Object System.Windows.Forms.Label) 212 47 500 20
$showLimit = { $lblDays.Text = "days or older by last modified date (before {0})" -f (Get-Date (Get-Date).Date.AddDays(-[int]$numDays.Value) -Format "yyyy/MM/dd") }
$numDays.Add_ValueChanged($showLimit); & $showLimit
$chkSub = Add-Ctl (New-Object System.Windows.Forms.CheckBox) 135 74 300 22; $chkSub.Text = "Include subfolders"; $chkSub.Checked = $true
$chkKey = Add-Ctl (New-Object System.Windows.Forms.CheckBox) 135 100 430 22
$chkKey.Text = "Also include everything in folders whose names contain:"; $chkKey.Checked = $true
$txtKey = Add-Ctl (New-Object System.Windows.Forms.TextBox) 570 100 205 23; $txtKey.Text = $defaultKeywords
$lbl = Add-Ctl (New-Object System.Windows.Forms.Label) 12 133 120 20; $lbl.Text = "Save ZIP to"
$txtDest = Add-Ctl (New-Object System.Windows.Forms.TextBox) 135 130 640 23
$btnDest = Add-Ctl (New-Object System.Windows.Forms.Button) 785 129 80 25; $btnDest.Text = "Browse..."
$btnDest.Add_Click({ Pick-Folder $txtDest })
$lbl = Add-Ctl (New-Object System.Windows.Forms.Label) 135 155 640 20
$lbl.Text = "If empty, the ZIP goes into a _zip-archive folder inside the folder to clean. Another drive or a NAS also works."
$btnList = Add-Ctl (New-Object System.Windows.Forms.Button) 12 180 200 32; $btnList.Text = "1. List files (nothing moves yet)"
$grid = Add-Ctl (New-Object System.Windows.Forms.DataGridView) 12 220 855 290
$grid.AllowUserToAddRows = $false; $grid.RowHeadersVisible = $false
$grid.AutoSizeColumnsMode = "Fill"
$col = New-Object System.Windows.Forms.DataGridViewCheckBoxColumn; $col.HeaderText = "Move"; $col.FillWeight = 8
[void]$grid.Columns.Add($col)
foreach ($c in @(@("Reason", 22), @("Last modified", 20), @("Size (KB)", 12), @("Path (inside the folder to clean)", 60))) {
$i = $grid.Columns.Add($c[0], $c[0]); $grid.Columns[$i].FillWeight = $c[1]; $grid.Columns[$i].ReadOnly = $true
}
$grid.Columns[3].DefaultCellStyle.Alignment = "MiddleRight"
$grid.Add_CurrentCellDirtyStateChanged({ if ($grid.IsCurrentCellDirty) { $grid.CommitEdit("CurrentCellChange") } })
$grid.Add_CellValueChanged({ Update-Total })
$lblTotal = Add-Ctl (New-Object System.Windows.Forms.Label) 12 517 855 20; $lblTotal.Text = "Press 1. List files to see the matching files here."
$chkRecycle = Add-Ctl (New-Object System.Windows.Forms.CheckBox) 12 545 470 22
$chkRecycle.Text = "After checking the ZIP, send the original files to the Recycle Bin"; $chkRecycle.Checked = $true
$btnMove = Add-Ctl (New-Object System.Windows.Forms.Button) 520 540 220 32; $btnMove.Text = "2. Move into a ZIP"; $btnMove.Enabled = $false
$btnClose = Add-Ctl (New-Object System.Windows.Forms.Button) 755 540 110 32; $btnClose.Text = "Close"
$btnClose.Add_Click({ $form.Close() })
$btnList.Add_Click({
$grid.Rows.Clear()
$folder = $txtFolder.Text.Trim().TrimEnd("\")
if (-not (Test-Path -LiteralPath $folder -PathType Container)) {
[void][System.Windows.Forms.MessageBox]::Show("Folder not found: $folder", "Check"); return
}
$script:root = (Resolve-Path -LiteralPath $folder).ProviderPath.TrimEnd("\")
$dest = Get-DestPath
$limit = (Get-Date).Date.AddDays(-[int]$numDays.Value)
$words = @($txtKey.Text.Split(",") | ForEach-Object { $_.Trim() } | Where-Object { $_ })
$found = [ordered]@{}
$form.Cursor = "WaitCursor"
if ($chkKey.Checked -and $words.Count -gt 0) {
$dirs = Get-ChildItem -LiteralPath $script:root -Directory -Recurse:$chkSub.Checked -ErrorAction SilentlyContinue
foreach ($d in $dirs) {
$hit = @($words | Where-Object { $d.Name.IndexOf($_, [StringComparison]::OrdinalIgnoreCase) -ge 0 })
if ($hit.Count -eq 0) { continue }
foreach ($f in Get-ChildItem -LiteralPath $d.FullName -File -Recurse -ErrorAction SilentlyContinue) {
if (-not $found.Contains($f.FullName)) { $found[$f.FullName] = @($f, "Folder name has $($hit[0])") }
}
}
}
foreach ($f in Get-ChildItem -LiteralPath $script:root -File -Recurse:$chkSub.Checked -ErrorAction SilentlyContinue) {
if ($f.LastWriteTime -lt $limit -and -not $found.Contains($f.FullName)) { $found[$f.FullName] = @($f, "Older than $([int]$numDays.Value) days") }
}
foreach ($v in $found.Values) {
$f = $v[0]
if ($f.FullName.StartsWith($dest + "\", [StringComparison]::OrdinalIgnoreCase)) { continue }
$rel = $f.FullName.Remove(0, $script:root.Length + 1)
$i = $grid.Rows.Add($true, $v[1], (Get-Date $f.LastWriteTime -Format "yyyy/MM/dd HH:mm"), ("{0:N0}" -f [math]::Ceiling($f.Length / 1KB)), $rel)
$grid.Rows[$i].Tag = $f
}
$form.Cursor = "Default"
Update-Total
if ($grid.Rows.Count -eq 0) { $lblTotal.Text = "No matching files." }
})
$btnMove.Add_Click({
$targets = @($grid.Rows | Where-Object { $_.Cells[0].Value } | ForEach-Object { $_.Tag })
$dest = Get-DestPath
$size = ($targets | Measure-Object Length -Sum).Sum / 1MB
$after = if ($chkRecycle.Checked) { "After checking the ZIP, the original files go to the Recycle Bin." } else { "The original files stay where they are." }
$msg = "Put {0} files ({1:N1} MB) into a ZIP.`nSave to: {2}`n{3}`n`nContinue?" -f $targets.Count, $size, $dest, $after
if ([System.Windows.Forms.MessageBox]::Show($msg, "Confirm", "YesNo", "Question") -ne "Yes") { return }
New-Item -ItemType Directory -Force -Path $dest | Out-Null
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
$zipPath = Join-Path $dest "old-files-$stamp.zip"
$csvPath = Join-Path $dest "old-files-$stamp.csv"
$form.Cursor = "WaitCursor"
$log = New-Object System.Collections.ArrayList
$zip = [System.IO.Compression.ZipFile]::Open($zipPath, "Create")
try {
$n = 0
foreach ($f in $targets) {
$n++
$rel = $f.FullName.Remove(0, $script:root.Length + 1)
$entry = $rel.Replace("\", "/")
$state = "Added"
try { [void][System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $f.FullName, $entry, "Optimal") }
catch { $state = "Not added (file in use?): " + $_.Exception.GetBaseException().Message }
[void]$log.Add([PSCustomObject]@{ Status = $state; OriginalPath = $f.FullName; NameInZip = $entry; Size = $f.Length; LastModified = $f.LastWriteTime })
if ($n % 20 -eq 0) { $lblTotal.Text = "Adding to ZIP {0} / {1}" -f $n, $targets.Count; [System.Windows.Forms.Application]::DoEvents() }
}
} finally { $zip.Dispose() }
# Reopen the ZIP. A file counts as checked only if its entry has the same name plus the same size
$check = @{}
$zip = [System.IO.Compression.ZipFile]::OpenRead($zipPath)
foreach ($e in $zip.Entries) { $check[$e.FullName] = $e.Length }
$zip.Dispose()
$ok = 0; $moved = 0; $ng = 0
foreach ($r in $log) {
if ($r.Status -ne "Added") { $ng++; continue }
if ($check[$r.NameInZip] -ne $r.Size) { $r.Status = "Left in place: ZIP entry did not match"; $ng++; continue }
$ok++
if ($chkRecycle.Checked) {
try {
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($r.OriginalPath, "OnlyErrorDialogs", "SendToRecycleBin")
$r.Status = "Added, original sent to Recycle Bin"; $moved++
} catch { $r.Status = "Added, but the original could not be moved: " + $_.Exception.GetBaseException().Message }
}
}
# Folders left empty also go to the Recycle Bin (the folder to clean itself stays)
if ($chkRecycle.Checked) {
$dirs = $log | ForEach-Object { Split-Path $_.OriginalPath -Parent } | Sort-Object -Unique | Sort-Object Length -Descending
foreach ($d in $dirs) {
while ($d.Length -gt $script:root.Length -and (Test-Path -LiteralPath $d) -and -not (Get-ChildItem -LiteralPath $d -Force)) {
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory($d, "OnlyErrorDialogs", "SendToRecycleBin")
$d = Split-Path $d -Parent
}
}
}
$opt = if ($PSVersionTable.PSVersion.Major -ge 6) { @{ Encoding = "utf8BOM" } } else { @{ Encoding = "UTF8"; NoTypeInformation = $true } }
$log | Export-Csv -LiteralPath $csvPath @opt
$form.Cursor = "Default"
$done = "Added to ZIP: {0}`nSent to Recycle Bin: {1}`nNot added or left in place: {2}`n`nZIP: {3}`nLog: {4}" -f $ok, $moved, $ng, $zipPath, $csvPath
[void][System.Windows.Forms.MessageBox]::Show($done, "Done")
$btnList.PerformClick()
})
[void]$form.ShowDialog()
Feel free to use and modify the script.
Settings in the window and the lines to edit
You can change every setting in the window each time. The first three lines only set the values the window starts with.
| Setting | What it does | Starting value (line to edit) |
|---|---|---|
| Folder to clean | Pick it with Browse. A NAS share works too | Downloads ($defaultFolder, line 2) |
| Days | Files last modified more than this many days ago are listed. The cutoff date is shown next to it | 90 ($defaultDays, line 3) |
| Include subfolders | Turn it off to look only at files directly in the folder | On |
| Folders whose names contain | Everything inside a folder whose name contains one of these words is listed, whatever its date. Separate words with commas. Not case-sensitive | old,archive ($defaultKeywords, line 4) |
| Save ZIP to | If empty, a _zip-archive folder is made inside the folder to clean. Another drive or a NAS works too | Empty |
| Send originals to the Recycle Bin | Turn it off to only make the ZIP and leave the originals in place | On |
Test run
I tested it on a folder set up like a Downloads folder, with 12 files whose last modified dates were moved back in time. The files inside the “old_2024” and “archive” folders were recent on purpose (2 to 10 days old).
With Days left at 90, pressing “1. List files” showed 9 files. Three came from the folders named “old_2024” and “archive”, whatever their dates. The other six were older than 90 days. A 5-day-old note, a 30-day-old Excel file and this week's file in the “sub” folder did not appear. I still need setup.exe, so I unchecked it.
Pressing “2. Move into a ZIP” shows the file count and the destination, and starts when you press Yes. To test a locked file, I kept in-use.log open in another program. When it finished, the tool showed this (paths shortened):
Added to ZIP: 7 Sent to Recycle Bin: 7 Not added or left in place: 1 ZIP: ...\Downloads\_zip-archive\old-files-20261126-073356.zip Log: ...\Downloads\_zip-archive\old-files-20261126-073356.csv
The ZIP kept the folder structure:
archive\invoice.pdf old_2024\a.txt old_2024\inner\b.csv big-file.bin photo[1].jpg quote_2025.pdf sub\old-notes.docx
The “old_2024” and “archive” folders were empty afterwards, so they went to the Recycle Bin as well. The “sub” folder stayed because this week's file is still in it. The list then refreshes and shows only setup.exe, which I unchecked, plus in-use.log, which was locked. In the refreshed list, every file is checked again.

A CSV log next to the ZIP records the result for each file (excerpt):
"Status","OriginalPath","NameInZip","Size","LastModified" "Added, original sent to Recycle Bin","...\Downloads\old_2024\a.txt","old_2024/a.txt","3030","2026/11/23 5:33:53" "Not added (file in use?): The process cannot access the file '...\Downloads\in-use.log' because it is being used by another process.","...\Downloads\in-use.log","in-use.log","3026","2026/05/10 5:33:53" "Added, original sent to Recycle Bin","...\Downloads\big-file.bin","big-file.bin","5242880","2026/01/30 5:33:53"
I ran the same test in PowerShell 5.1 and 7, and both gave the same result.
How to restore
To get back one or two files, open the ZIP in File Explorer and drag them out. To put everything back where it was, use this one line. Change the ZIP path and the destination (the folder you cleaned).
Expand-Archive -LiteralPath "$env:USERPROFILE\Downloads\_zip-archive\old-files-20261126-073356.zip" -DestinationPath "$env:USERPROFILE\Downloads"
Files from subfolders go back to the same subfolders. If a file with the same name already exists, Expand-Archive stops with an error instead of overwriting it. In my test, every restored file matched the original byte for byte, in both 5.1 and 7.
Things that tripped me up
Files in use cannot go into the ZIP
A file that another program has open cannot be read, so it cannot be added. The tool skips it, keeps going and leaves it in place. The CSV log says “Not added (file in use?)”, so close the program and list the files again.
Use -LiteralPath for names with square brackets
With a name like “photo[1].jpg”, -Path treats the brackets as a wildcard and may not find the file. The script uses -LiteralPath so names are taken as they are. In the test, photo[1].jpg went into the ZIP and came back without problems.
Restored files can be up to 2 seconds off
A ZIP stores the last modified time in 2-second steps. After restoring, some files were 1 to 2 seconds off from the original time, while the contents matched. That does not matter for sorting by date or for this tool's day count, but keep it in mind if something compares times to the second.
Related posts
To see what is in a folder before moving anything, export a file list to CSV for Excel. To add dates or numbers to file names, see bulk rename files with a one-line undo. To copy a whole folder to a NAS every day without zipping it, see daily Robocopy backup to a NAS.
Summary
- Instead of deleting old files straight away, list them, put them into a ZIP and send the originals to the Recycle Bin
- You pick the days and folder name words like “old” in the window, and unchecked files are not moved
- Only files confirmed inside the ZIP are moved, and a CSV log is saved. Expand-Archive puts them back in one line


Comments