0

I am new to Powershell and i need help in renaming multiple video files. So a folder contains files named as below;

  1. Episode S01E01.mkv 
  2. Episode S01E02.mkv 
  3. Episode S01E03.mkv
  …
  …
350. Episode S01E350.mkv

I am trying to build a script that would change the file name from Episode S01E*.mkv to "S01E*.mkv.

I tried to use this script but for the life of me i cannot modify it to my requirement;

$counter = 01
Get-ChildItem *.mkv | ForEach-Object {$newName = "S01E$counter" + $_.Extension Rename-Item $_.FullName -NewName $newName $counter++}
4
  • 4
    So what have you tried? We are not a PowerShell script writing service Commented Oct 18, 2025 at 22:12
  • I tried using this command but i cannot seem to modify it to my requirement, $counter = 01 Get-ChildItem *.mkv | ForEach-Object {$newName = "S01E$counter" + $_.Extension Rename-Item $_.FullName -NewName $newName $counter++} Commented Oct 18, 2025 at 22:22
  • 2
    Are you just trying to remove episode from the name? Commented Oct 19, 2025 at 0:24
  • Hop over and ask stackoverflow.ai as it has suggestions too. Commented Oct 19, 2025 at 18:29

1 Answer 1

6

Using a counter is possibly a bad idea unless you can guarantee that the result of Get-ChildItem is in order.

If you're just trying to remove the string episode from the name, it would be much safer to just use replace.

Get-ChildItem *.mkv |
  ForEach-Object {
    $name = $_.Name -replace 'Episode ', ''
    if ($name -ne $_.Name) {
      Rename-Item $_.FullName -NewName $name
      }
    }

(not tested, typed on mobile so might need to be adjusted)

1
  • 1
    @Velvet -- thanks for explaining the sh stuff ... and fixing it back. [grin] Commented Oct 20, 2025 at 6:14

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.