Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set the path of the folder where the files are located
- $sourcePath = "D:\RPG Pack"
- # Check if the folder exists
- if (-Not (Test-Path $sourcePath)) {
- Write-Host "The specified folder does not exist!" -ForegroundColor Red
- exit
- }
- # Get all files in the folder (regardless of extension)
- $files = Get-ChildItem -Path $sourcePath -File
- foreach ($file in $files) {
- # Get the file name without extension
- $baseName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
- # Remove everything inside parentheses (e.g., region info) and brackets (e.g., translation/hack info)
- $cleanBaseName = $baseName -replace "\s*\(.*?\)", "" -replace "\s*\[.*?\]", ""
- # Trim any remaining trailing or leading whitespace
- $cleanBaseName = $cleanBaseName.Trim()
- # Get the original extension
- $extension = $file.Extension
- # Combine the cleaned name with the original extension
- $newName = "$cleanBaseName$extension"
- # Build the full path for the renamed file
- $newPath = Join-Path -Path $sourcePath -ChildPath $newName
- # Rename the file if the name has changed
- if ($file.Name -ne $newName) {
- Rename-Item -Path $file.FullName -NewName $newName -Force
- Write-Host "Renamed: $($file.Name) -> $newName"
- }
- }
- Write-Host "Process completed!" -ForegroundColor Green
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement