0
votes

So I was redownloading my google drive backup and I noticed that in every file no matter how deep in my directory and or subdirectory it had in its name a "(1)" and I was wondering about removing this. Iv gotten to get-childitem . | foreach { rename-item $_ $_.Name.Replace(" (1)", "") } but thats only for this directory and I need to go deeper a lot deeper. Thanks in advance.

update: got to "get-childitem -recurse | rename-item -newname { $_.name -replace " (1)", ""}" however it throws an error: rename-item : Source and destination path must be different. At line:1 char:26

  • ... lditem -recurse | rename-item -newname { $_.name -replace " (1)", ""}
  •                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : WriteError: (C:\Users\Opti\D...rgs (1)\lib (1):String) [Rename-Item], IOException
    • FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand

edit: Get-ChildItem -Path "C:\My\Root\Path" -Filter "(1)" -Recurse | Foreach {Rename-Item -Path $.FullName -NewName $.Name.Replace('(1)','')} ^ this is what worked for me

2

2 Answers

1
votes

How about this?

Get-ChildItem -Path "C:\My\Root\Path" -Recurse | Foreach {Rename-Item -Path $_.FullName -NewName $_.Name.Replace('(1)','')}
0
votes

Use the recurse flag to search nested folders.

Get-Childitem -Path "C:\My\Root\Path" -Recurse | [do stuff]