sturdybits

Guides / Tidy Folders

How to sort files into folders by type or date automatically, for free

30 November 2026

To sort files into folders by type or date for free, use a short PowerShell script on Windows, a few lines in Terminal on a Mac, or the free organize tool on either. Whichever you use, run it first in a mode that only shows what it would do, make sure it can't delete or overwrite anything, and know how you'd put things back.

Before you run anything

1. A PowerShell script (Windows)

Good for: sorting by type or month, with a preview, a way back and nothing to install.

Open PowerShell from the Start menu, paste this in, change the first line if your folder is elsewhere, and press Enter:

$folder = "$HOME\Downloads"
$preview = $true   # change to $false to move the files
$types = @{
    Documents     = 'doc docx odt rtf txt pages'
    PDFs          = 'pdf'
    Spreadsheets  = 'xls xlsx xlsm csv ods numbers'
    Presentations = 'ppt pptx odp key'
    Pictures      = 'jpg jpeg png gif heic webp bmp tif tiff'
    Videos        = 'mp4 mov avi mkv wmv webm'
    Music         = 'mp3 m4a wav flac aac ogg'
    Archives      = 'zip rar 7z gz tar'
    Installers    = 'exe msi msix dmg pkg'
}
$log = Join-Path $folder 'sorted-files.csv'
(Get-ChildItem -LiteralPath $folder -File) | ForEach-Object {
    $ext = $_.Extension.TrimStart('.').ToLower()
    if ($_.Name -eq 'sorted-files.csv' -or $_.Name -like '~$*' -or $ext -in 'crdownload', 'part', 'tmp') { return }
    $type = 'Other'
    foreach ($t in $types.Keys) { if (($types[$t] -split ' ') -contains $ext) { $type = $t } }
    $dir = Join-Path $folder $type
    $to = Join-Path $dir $_.Name
    $n = 2
    while (Test-Path -LiteralPath $to) {
        $to = Join-Path $dir ('{0} ({1}){2}' -f $_.BaseName, $n++, $_.Extension)
    }
    if (-not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Path $dir -WhatIf:$preview | Out-Null }
    Move-Item -LiteralPath $_.FullName -Destination $to -ErrorAction Stop -WhatIf:$preview
    [pscustomobject]@{ From = $_.FullName; To = $to } |
        Export-Csv -LiteralPath $log -Append -NoTypeInformation -Encoding UTF8 -WhatIf:$preview
}

With $preview = $true, every change runs with -WhatIf, so PowerShell prints a "What if" line for each folder it would make and each file it would move, and changes nothing. When the list looks right, set $preview = $false and run it again.

It sorts only the files at the top of the folder, leaves Office lock files (names starting ~$) and unfinished downloads alone, and puts anything it doesn't recognise in Other. If a name is taken, it adds a number, such as Invoice (2).pdf, and Move-Item stops with an error rather than replace a file. Each move is added to sorted-files.csv in the folder. If a file can't be moved, it stops there.

To sort by month instead, into folders such as 2026-11, replace the line starting foreach with this, which uses each file's modified date:

    $type = $_.LastWriteTime.ToString('yyyy-MM')

To put everything back, run this, again with a preview first:

$folder = "$HOME\Downloads"
$preview = $true
Import-Csv -LiteralPath (Join-Path $folder 'sorted-files.csv') | ForEach-Object {
    if ((Test-Path -LiteralPath $_.To) -and -not (Test-Path -LiteralPath $_.From)) {
        Move-Item -LiteralPath $_.To -Destination $_.From -WhatIf:$preview
    }
}

A file goes back only if it's still where the script put it and its old place is free. The new folders are left empty for you to remove.

2. Terminal on a Mac

Good for: sorting by extension or month, with nothing to install.

Open Terminal and paste:

cd ~/Downloads
for f in *.*; do
  [ -f "$f" ] || continue
  ext=$(printf '%s' "${f##*.}" | tr '[:upper:]' '[:lower:]')
  echo mkdir -p "$ext"
  echo mv -n "./$f" "$ext/"
done

With echo in front, it only prints the commands it would run. When they look right, delete both echos and run it again. Each file goes into a folder named after its extension, such as pdf. mv -n never overwrites, so a file whose name is taken stays where it is. Folders, hidden files and files without an extension are skipped.

To sort by month, change *.* to * and the ext= line to ext=$(stat -f '%Sm' -t '%Y-%m' "$f"), which reads each file's modified date. It keeps no list of moves, so try it on a copy first.

3. organize (Windows, Mac and Linux)

Good for: rules you can run again, with a simulation built in.

organize is free and open source. It needs Python: install it with pip install -U organize-tool, run organize new, then organize edit to open its rules file, and write rules such as:

rules:
  - name: "PDFs"
    locations: "~/Downloads"
    filters:
      - extension: pdf
    actions:
      - move: "~/Downloads/PDFs/"
  - name: "Pictures by month"
    locations: "~/Downloads"
    filters:
      - extension: [jpg, jpeg, png, heic]
      - lastmodified
    actions:
      - move: "~/Downloads/Pictures/{lastmodified.strftime('%Y-%m')}/"

organize sim shows what would happen and changes nothing; organize run does it. Subfolders are left alone unless a rule says subfolders: true, and the move action adds a number when a name is taken. Don't use its delete or trash actions. It has no undo command.

When a tool is quicker

Scripts need care, and only the PowerShell one above can put things back. Tidy Folders does the same job in your browser, with nothing to install or edit.

Choose a folder and start from a plan (by type, by type then year, by year and month, or by extension), or add rules in plain words, such as names containing Invoice go into Invoices. You see where every file will go before anything moves. Code projects, app bundles, shortcuts, open documents and unfinished downloads are left alone.

In Chrome or Edge on a computer, the files then move, each one checked, and nothing is deleted or overwritten. Put them all back undoes the lot, and a log saved in the folder lets you do it another day. Firefox and Safari show the plan but can't move files. Your files never leave your computer. The plan is free for any folder; the free version moves up to 50 files at a time, putting back is always free, and Pro is £15 once. You can try it with a sample folder first.

Quick answers

Can I undo it? With the PowerShell script, yes: the second script uses its list to put files back. The Mac loop and organize keep no list, so try them on a copy first.

Can it run by itself every day? Once you've tested it by hand, Task Scheduler on Windows or launchd on a Mac can run a script on a schedule. Apps such as Hazel and File Juggler sort files as they arrive: see how to organise your Downloads folder.

Will it overwrite files with the same name? Not with any method here: the PowerShell script and organize add a number, and mv -n leaves the file where it is.