swapping 12851 files names to 12851 files in a another folder

swapping 12851 files names to 12851 files in a another folder using powershell i have a text file with all the new names or i have both directory locations saved as text which is as follows E:\Games\my fallout 4 mods\rick and morty audio\test audio no dlc\RICK MOD TESTS\Sound\Voice\Fallout4.esm\PlayerVoiceMale01 is the directory that hs the new names
E:\Games\my fallout 4 mods\rick and morty audio\winraw folder\wave files1 is the direcorty with files that need renamed i planned on using a text file to renmes them and came up with a power shell scrpit whats wrong with it $RenameTable = @{}
Get-Content newnames.txt |ForEach-Object {
$OldName,$NewName = $_.Split(‘|’)
$RenameTable[$OldName] = $NewName
}

Get-ChildItem E:\Games\my fallout 4 mods\rick and morty audio\winraw folder\wave files1 |Rename-Item -NewName {
if($RenameTable.ContainsKey($.Name)){
$RenameTable[$
.Name]
} else {
$_.Name
}
}

this is the error i keep getting i dont understand
Get-ChildItem : A positional parameter cannot be found that accepts argument ‘4’.
At line:1 char:14

  • Get-ChildItem <<<< E:\Games\my fallout 4 mods\rick and morty audio\winraw folder\wave files1 |Rename-Item -NewName
    {
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ChildItem], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Because the path contains spaces it needs to be enclosed in quotes.
try this

Get-ChildItem "E:\Games\my fallout 4 mods\rick and morty audio\winraw folder\wave files1" |Rename-Item -NewName {
if($RenameTable.ContainsKey($_.Name)){
$RenameTable[$_.Name]
} else {
$_.Name
}
}

that was the issue awesome man thanks very much so i ran it and this is what happended on every one Cannot index into a null array.
At line:3 char:14

  • $RenameTable[ <<<< $OldName] = $NewName
    • CategoryInfo : InvalidOperation: (00249AD5_1:String) , RuntimeException
    • FullyQualifiedErrorId : NullArray any ideas aand

I got it figured out

It is the way you are trying to populate the $RenameTable

I used this it test the concept

$RenameTable = @{}
Get-Content newnames.txt |ForEach-Object {
    $temp = $_.Split('|')
    $RenameTable[$temp[0]] = $temp[1]
}

This holds the line being read from the newnames.txt file in the $temp variable. This is an array created by the split on the “|”. Using the 0 value in place of $oldname and the 1 value in place of $newname should work for you.

that solved it for me perfectly thank you very much