Search This Blog

2013-01-26

PowerShell: Rename File With Regular Expression

ls *.rmvb | %{$_.name -replace 'TVBOXNOW ','' -replace '_1280x720',''}

From:
TVBOXNOW 大太監 CH18_1280x720.rmvb
TVBOXNOW 大太監 CH19_1280x720.rmvb
TVBOXNOW 大太監 CH20_1280x720.rmvb
TVBOXNOW 大太監 CH21_1280x720.rmvb

To:
大太監 CH18.rmvb
大太監 CH19.rmvb
大太監 CH20.rmvb
大太監 CH21.rmvb
大太監 CH22.rmvb
大太監 CH23.rmvb
大太監 CH24.rmvb
大太監 CH25.rmvb


Rename by removing following:
1. "TVBOXNOW "
2. "_1280x720"

ls *.rmvb | %{ren $_  $($_.name -replace 'TVBOXNOW ','' -replace '_1280x720','')}

No comments: