Powershell删除方括号内

时间:2016-10-04 20:24:31

标签: powershell cmd command-prompt

我有这些名字的文件:

Aaron Wilde - Awaken.mp3
Aaron Wilde - Heroes Collide [Hybrid Orchestral, Action Music].mp3
Aaron Wilde - Into The Fire [Hybrid Orchestral, Heroic, Uplifting Music].mp3
Aaron Wilde - Legacy [Hybrid Orchestral, Vocal, Heroic].mp3
Aaron Wilde - Miracles [Fantasy, Emotional Music].mp3
Aaron Wilde - Together We Rise [Heroic, Orchestral, Battle Music].mp3

我想在文件名中重命名不带括号的文件。我试过这个,但它没有用。

 get-childitem *.mp3 | foreach { move-item -literalpath $_.name $_.name.replace("``[*``]","")}

1 个答案:

答案 0 :(得分:3)

  1. 字符串.Replace方法适用于文字字符串,请使用-replace运算符。
  2. 而不是“使用\.*代替*
    .表示任何符号,*表示0次或更多次出现
  3. move-item -literalpath $_.name ($_.name -replace '\[.*\]', '')
    
相关问题