rename files in powershell

后端 未结 2 973
醉梦人生
醉梦人生 2021-01-24 20:12

I would like to ask for help in renaming files in given folder.

I would like to change characters \"vol._\" to \"vol.\"

thanks for help

相关标签:
2条回答
  • 2021-01-24 20:30
     gci c:\folder_path | ? {$_.name -match 'vol._'} | 
         rename-item -newname {$_.name  -replace 'vol._','vol.'} -whatif
    

    Take a look at the output and if everything works fine remove whatif switch

    edit. If you need to rename files even in subfolders you have to apply a little change

     gci c:\folder_path -rec | ? {!$_.psiscontainer -and $_.name -match 'vol._'} |
         rename-item -newname {$_.name  -replace 'vol._','vol.'} -whatif
    
    0 讨论(0)
  • 2021-01-24 20:34

    What about:

    gci c:\folderpath -include vol._* | rename-item -newname {$_.name -replace 'vol._', 'vol.'}
    
    0 讨论(0)
提交回复
热议问题