PowerShell guide

Move files automatically
with PowerShell.

If you're happy with a script, PowerShell and Task Scheduler can sort a folder on a timer for free. Here's a working script, how to test it without moving anything, and how to schedule it. And if you'd rather not maintain a script, the no-code version is at the end.

1. The script

Save this as C:\Scripts\sort-downloads.ps1. Each destination folder lists the file extensions that go there; edit them to suit you.

# sort-downloads.ps1: move files out of Downloads by type
$source = "$env:USERPROFILE\Downloads"
$rules = [ordered]@{
  "$env:USERPROFILE\Documents" = @(".pdf", ".doc", ".docx", ".xlsx", ".txt")
  "$env:USERPROFILE\Pictures"  = @(".jpg", ".jpeg", ".png", ".heic")
  "$env:USERPROFILE\Archives"  = @(".zip", ".7z", ".rar")
}

Get-ChildItem -Path $source -File | ForEach-Object {
  $file = $_
  foreach ($dest in $rules.Keys) {
    if ($rules[$dest] -contains $file.Extension.ToLower()) {
      New-Item -ItemType Directory -Path $dest -Force | Out-Null
      Move-Item -Path $file.FullName -Destination $dest -WhatIf
      break
    }
  }
}

2. Test it before it moves anything

The -WhatIf on Move-Item makes PowerShell print what it would move without touching a file. Run the script, read the list, and only when it looks right delete -WhatIf and save.

3. Run it on a schedule

Task Scheduler can run it every 15 minutes:

  1. 1Open Task Scheduler and choose Create Task.
  2. 2On Triggers, add a new trigger: At log on, then tick Repeat task every 15 minutes for a duration of Indefinitely.
  3. 3On Actions, add Start a program with powershell.exe as the program and these arguments:
    -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Scripts\sort-downloads.ps1"

Where scripts get awkward

The script works, but it's yours to maintain: name clashes, files still downloading, a typo that moves the wrong things, and no undo once -WhatIf is gone. TidyFile does the same job with rules you set up in a window: a preview before it touches existing files, an activity log you can undo from, and new files moved the moment they arrive rather than every 15 minutes. More on that in how to automatically move files.

The TidyFile rule

Documents out of Downloads

When a file
in Downloads · type is pdf, doc, docx, xlsx, txt
Then
move to Documents

Set it up once and TidyFile applies it in the background, to new files the moment they arrive. Preview what it'll do to the files already there, and undo anything from the activity log.

Questions

What happens if a file with the same name already exists?+

Move-Item stops with an error for that file and leaves it where it is. Add a check with Test-Path and rename the file first if you want duplicates kept, or use a tool that handles clashes for you.

Can PowerShell move files the moment they arrive?+

Yes, with System.IO.FileSystemWatcher, but the script has to stay running, survive restarts and cope with files that are still downloading. A scheduled task every 15 minutes is simpler and good enough for most people.

Why does Windows say running scripts is disabled?+

PowerShell's execution policy blocks unsigned scripts by default. Passing -ExecutionPolicy Bypass in the scheduled task runs just this script without changing the setting for your whole PC.