Powershell - Rename filename by removing the last few characters

前端 未结 3 745
说谎
说谎 2021-01-19 01:02

I want to remove the last 11 characters of multiple files names. For example I have these file names:

ABCDE_2015_10_20
HIJKL_2015_10_20
MNOPQ_2015_10_20
RSTU         


        
3条回答
  •  长发绾君心
    2021-01-19 01:46

    You're almost there, you just need to tell substring exactly where to start and end:

    Get-ChildItem 'E:\Thomson Reuters\Stage' | rename-item -newname { $_.name.substring(0,$_.name.length-11) } 
    

    By passing two integers to substring you give it the StartIndex and Length of the string you want to capture. See here for the documentation

提交回复
热议问题