Created
December 26, 2019 05:22
-
-
Save Pxtl/daed801def23a08cb81c6b8b771d69d6 to your computer and use it in GitHub Desktop.
Rename Bin/Cue file using Powershell - designed for PS1 files
This file contains 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
# for a given cue/bin pair, rename the bin file, rename the cue file with the corresponding name, | |
# and update the bin reference within the cue file to match | |
[cmdletbinding()] | |
param( | |
[Parameter(Mandatory)][io.FileInfo]$sourceBinPath, | |
[Parameter(Mandatory)][string]$newName | |
) | |
$sourceCuePath = [io.path]::ChangeExtension($sourceBinPath, 'cue') | |
write-verbose("sourceCuePath: $sourceCuePath") | |
$sourceBinName = [io.path]::GetFileName($sourceBinPath) | |
write-verbose("sourceBinName: $sourceBinName") | |
$newBinName = [io.path]::ChangeExtension($newName, 'bin') | |
write-verbose("newBinName: $newBinName") | |
$newBinNameNoDirectory = [io.path]::GetFileName($newBinName) | |
$newCueName = [io.path]::ChangeExtension($newName, 'cue') | |
write-verbose("newCueName: $newCueName") | |
$sourceBinRegex = "FILE `"$([Regex]::Escape($sourceBinName))`" BINARY" | |
write-verbose("sourceBinRegex: $sourceBinRegex") | |
#replace the reference to the bin within the cue file to the new name | |
((Get-Content -path $sourceCuePath -Raw) -replace $sourceBinRegex,"FILE `"$newBinNameNoDirectory`" BINARY") | Set-Content -Path $sourceCuePath | |
Rename-Item $sourceBinPath $newBinName | |
Rename-Item $sourceCuePath $newCueName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment