replace names of all directiories and files in PS

前端 未结 3 703
忘了有多久
忘了有多久 2021-01-05 18:56

I want to replace all space characters into \"_\" in names of all subfolders and files. Unfortunately when I type:

Get-ChildItem -recurse -name | ForEach-Obj         


        
3条回答
  •  青春惊慌失措
    2021-01-05 19:42

    Don't use the Name switch, it outputs only the names of the objects, not their full path. Try this:

    Get-ChildItem -Recurse | `
       Where-Object {$_.Name -match ' '} | `
         Rename-Item -NewName { $_.Name -replace ' ','_' }
    

提交回复
热议问题