Advertisement
hirukolock

Rename Roms

Apr 9th, 2025 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Set the path of the folder where the files are located
  2. $sourcePath = "D:\RPG Pack"
  3.  
  4. # Check if the folder exists
  5. if (-Not (Test-Path $sourcePath)) {
  6.     Write-Host "The specified folder does not exist!" -ForegroundColor Red
  7.     exit
  8. }
  9.  
  10. # Get all files in the folder (regardless of extension)
  11. $files = Get-ChildItem -Path $sourcePath -File
  12.  
  13. foreach ($file in $files) {
  14.     # Get the file name without extension
  15.     $baseName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
  16.  
  17.     # Remove everything inside parentheses (e.g., region info) and brackets (e.g., translation/hack info)
  18.     $cleanBaseName = $baseName -replace "\s*\(.*?\)", "" -replace "\s*\[.*?\]", ""
  19.  
  20.     # Trim any remaining trailing or leading whitespace
  21.     $cleanBaseName = $cleanBaseName.Trim()
  22.  
  23.     # Get the original extension
  24.     $extension = $file.Extension
  25.  
  26.     # Combine the cleaned name with the original extension
  27.     $newName = "$cleanBaseName$extension"
  28.  
  29.     # Build the full path for the renamed file
  30.     $newPath = Join-Path -Path $sourcePath -ChildPath $newName
  31.  
  32.     # Rename the file if the name has changed
  33.     if ($file.Name -ne $newName) {
  34.         Rename-Item -Path $file.FullName -NewName $newName -Force
  35.         Write-Host "Renamed: $($file.Name) -> $newName"
  36.     }
  37. }
  38.  
  39. Write-Host "Process completed!" -ForegroundColor Green
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement