A set of PowerShell scripts for automatic file organization on USB drives, local folders, or any directory.
| Script | Description |
|---|---|
Sort-FilesByType.ps1 |
Sorts files into folders by type: Photos, Videos, PDF, Others |
Sort-FilesByDate.ps1 |
Sorts files into folders by modification/creation/EXIF date |
Rename-PhotosVideos.ps1 |
Renames photos and videos to dd-MM-yyyy Photo/Video N.ext |
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser$sourcePath = "F:\Photos" # ← your folder here.\Sort-FilesByType.ps1
.\Sort-FilesByDate.ps1
.\Rename-PhotosVideos.ps1 -PhotosRoot "F:\Photos" -VideosRoot "F:\Videos" -WhatIfScans a source folder and moves files into subfolders based on their extension.
Output folder structure:
F:\
├── Photos\ ← .jpg, .png
├── Videos\ ← .mp4
├── PDF\ ← .pdf
└── Others\ ← everything else
Settings:
| Variable | Description |
|---|---|
$sourcePath |
Root folder (e.g. USB drive F:\) |
$destPath |
Folder to scan for files (e.g. F:\New) |
Features:
- Uses
Move-Iteminstead of Copy + Delete — much faster, especially for large video files - Creates destination folders automatically if they don't exist
- Removes empty folders after sorting
- Handles read errors gracefully without stopping execution
Scans a folder and moves files into subfolders named by date.
Output folder structure:
F:\Photos\
├── 01.2023\
├── 06.2024\
├── 12.2024\
└── 05.2025\
Settings:
| Variable | Default | Description |
|---|---|---|
$sourcePath |
F:\Photos |
Folder to sort |
$dateSource |
exif |
Date source: exif / modified / created |
$folderFormat |
MM.yyyy |
Folder name format (see below) |
$dateSource options:
| Value | Behaviour |
|---|---|
exif |
Reads the original shoot date from EXIF metadata (JPG/TIFF). Falls back to LastWriteTime if EXIF is absent |
modified |
Uses the file's last modification date |
created |
Uses the file's creation date |
⚠️ LastWriteTimechanges when a file is copied. Useexiffor photos to get the actual shoot date.
$folderFormat examples:
| Value | Example folder |
|---|---|
MM.yyyy |
05.2024 |
yyyy-MM |
2024-05 |
yyyy\\MM |
2024\05 (nested) |
yyyy |
2024 (year only) |
Features:
- EXIF date extraction via
System.Drawing— no third-party dependencies - Duplicate filename protection:
photo.jpg→photo_1.jpg→photo_2.jpg - Folder creation cache — avoids repeated filesystem calls for the same folder
- Skips files already in the correct date folder (safe to re-run)
- Removes empty folders after sorting
- Progress bar with live stats
- Error log saved to
sort_errors.login the source folder
Renames photos and videos inside MM.yyyy date folders (the same folder structure
produced by Sort-FilesByDate.ps1) to a clean, consistent naming scheme.
Output naming:
F:\Photos\01.2023\
├── 05-01-2023 Photo 1.jpg
├── 05-01-2023 Photo 2.jpg
├── 06-01-2023 Photo 1.jpg
└── 06-01-2023 Photo 2.jpg
F:\Videos\01.2023\
├── 05-01-2023 Video 1.mp4
└── 06-01-2023 Video 1.mp4
Parameters:
| Parameter | Description |
|---|---|
-PhotosRoot |
Path to the Photos folder (contains MM.yyyy subfolders) |
-VideosRoot |
Path to the Videos folder (contains MM.yyyy subfolders) |
-WhatIf |
Preview mode — shows the planned renames without changing anything |
How the date is determined (in priority order):
- Extracted from the file name, if it contains a date in
YYYYMMDDformat (e.g.IMG_20230105_...) - Falls back to the file's
LastWriteTimeif no date can be extracted from the name
Numbering:
- The counter (
N) resets for each individual date — all files from05-01-2023are numbered1, 2, 3..., then files from06-01-2023start again from1 - Files within the same date are ordered by their modification time
Features:
- Separate extension lists and labels for photos (
Photo) and videos (Video) - Skips files that are already correctly named — safe to re-run
- Adds a numeric suffix
(2),(3)... if a target filename is already taken -WhatIfpreview mode to check results before committing to a real rename
Example usage:
# Preview only, no files changed
.\Rename-PhotosVideos.ps1 -PhotosRoot "F:\Photos" -VideosRoot "F:\Videos" -WhatIf
# Actually rename the files
.\Rename-PhotosVideos.ps1 -PhotosRoot "F:\Photos" -VideosRoot "F:\Videos"
# Photos only
.\Rename-PhotosVideos.ps1 -PhotosRoot "F:\Photos"All scripts are non-destructive by design:
Sort-FilesByType.ps1/Sort-FilesByDate.ps1move files, never delete — no data is lostRename-PhotosVideos.ps1only renames files, it never moves or deletes them- Duplicate filenames are renamed, not overwritten
- Already-sorted / already-renamed files are skipped, so scripts can be re-run safely
- All errors are caught and logged without stopping execution
Rename-PhotosVideos.ps1supports-WhatIffor a safe dry run before any real change
| Requirement | Details |
|---|---|
| PowerShell | 5.1 or later (built into Windows 10/11) |
| .NET | System.Drawing assembly (included with Windows) |
| Permissions | Read + Write access to the source folder |
PowerShell 7+ is recommended for best compatibility. Download: github.com/PowerShell/PowerShell
Sort-FilesByDate.ps1
Starting sort: F:\Photos
Files found: 1,842
============================
Sort completed
============================
Total files: 1842
Moved: 1835
Already sorted: 6
Errors: 1
Empty dirs removed: 12
Log: F:\Photos\sort_errors.log
============================
Rename-PhotosVideos.ps1
=== Processing Photos (F:\Photos) ===
1000002044.jpg -> 05-01-2023 Photo 1.jpg
1000002046.jpg -> 06-01-2023 Photo 1.jpg
1000002047.jpg -> 06-01-2023 Photo 2.jpg
IMG_20230105_133345931.jpg -> 05-01-2023 Photo 2.jpg
=== Processing Videos (F:\Videos) ===
VID_20230105_141217.mp4 -> 05-01-2023 Video 1.mp4
MIT — free to use, modify, and distribute.