Created
January 27, 2026 17:29
-
-
Save hamada147/7ea472509535dcf7941fdd6332a3c970 to your computer and use it in GitHub Desktop.
File Renamer Script - Removes space between Season and Episode numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File Renamer Script - Removes space between Season and Episode numbers | |
| # Example: "S01 E11" becomes "S01E11" | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$FolderPath | |
| ) | |
| # Validate folder exists | |
| if (-not (Test-Path -Path $FolderPath -PathType Container)) { | |
| Write-Host "Error: Folder '$FolderPath' does not exist." -ForegroundColor Red | |
| exit 1 | |
| } | |
| # Get all files in the folder | |
| $files = Get-ChildItem -Path $FolderPath -File | |
| # Pattern to match "S## E##" (with space) | |
| $pattern = '(S\d+)\s+(E\d+)' | |
| $renamedCount = 0 | |
| foreach ($file in $files) { | |
| if ($file.Name -match $pattern) { | |
| # Replace "S## E##" with "S##E##" (remove the space) | |
| $newName = $file.Name -replace $pattern, '$1$2' | |
| $newPath = Join-Path -Path $FolderPath -ChildPath $newName | |
| Write-Host "Renaming: $($file.Name)" -ForegroundColor Yellow | |
| Write-Host " To: $newName" -ForegroundColor Green | |
| Rename-Item -Path $file.FullName -NewName $newName | |
| $renamedCount++ | |
| } | |
| } | |
| Write-Host "`nCompleted! Renamed $renamedCount file(s)." -ForegroundColor Cyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment