Skip to content

About

Sorting of photos and videos + other files

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

📁 PowerShell File Sorter

A set of PowerShell scripts for automatic file organization on USB drives, local folders, or any directory.


📜 Scripts

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

🚀 Quick Start

1. Allow script execution (run once as Administrator)

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

2. Edit the settings at the top of the script

$sourcePath = "F:\Photos"   # ← your folder here

3. Run the script

.\Sort-FilesByType.ps1
.\Sort-FilesByDate.ps1
.\Rename-PhotosVideos.ps1 -PhotosRoot "F:\Photos" -VideosRoot "F:\Videos" -WhatIf

📂 Sort-FilesByType.ps1

Scans 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-Item instead 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

📅 Sort-FilesByDate.ps1

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

⚠️ LastWriteTime changes when a file is copied. Use exif for 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.log in the source folder

🔤 Rename-PhotosVideos.ps1

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):

  1. Extracted from the file name, if it contains a date in YYYYMMDD format (e.g. IMG_20230105_...)
  2. Falls back to the file's LastWriteTime if no date can be extracted from the name

Numbering:

  • The counter (N) resets for each individual date — all files from 05-01-2023 are numbered 1, 2, 3..., then files from 06-01-2023 start again from 1
  • 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
  • -WhatIf preview 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"

🛡️ Safety

All scripts are non-destructive by design:

  • Sort-FilesByType.ps1 / Sort-FilesByDate.ps1 move files, never delete — no data is lost
  • Rename-PhotosVideos.ps1 only 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.ps1 supports -WhatIf for a safe dry run before any real change

⚙️ Requirements

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


📋 Example Output

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

📄 License

MIT — free to use, modify, and distribute.

About

Sorting of photos and videos + other files

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages