rename files in powershell

后端 未结 2 977
醉梦人生
醉梦人生 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
    

提交回复
热议问题