swapping 12851 files names to 12851 files in a another folder

This topic contains 6 replies, has 2 voices, and was last updated by Profile photo of Wayne Leggett Jr. Wayne Leggett Jr. 7 months, 1 week ago.

  • Author
    Posts
  • #38455
    Profile photo of Wayne Leggett Jr.
    Wayne Leggett Jr.
    Participant

    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
    }
    }

  • #38456
    Profile photo of Wayne Leggett Jr.
    Wayne Leggett Jr.
    Participant

    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: (:) [Get-ChildItem], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

  • #38457
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    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
    }
    }
    
  • #38458
    Profile photo of Wayne Leggett Jr.
    Wayne Leggett Jr.
    Participant

    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

  • #38461
    Profile photo of Wayne Leggett Jr.
    Wayne Leggett Jr.
    Participant

    I got it figured out

  • #38462
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    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.

  • #38464
    Profile photo of Wayne Leggett Jr.
    Wayne Leggett Jr.
    Participant

    that solved it for me perfectly thank you very much

You must be logged in to reply to this topic.