0

I have a bunch of files in Windows that have prefix and a suffix that needs to be removed.

For example

[video] Home Video - 014 Sunday Night[480p] [x265] [robert].mkv
[video] Home Video - 015 Monday Night[480p] [x265] [robert].mkv
[video] Home Video - 016 Tuesday Night[480p] [x265] [robert].mkv

I want to rename these files so it will say

014 Sunday Night
015 Monday Night
016 Tuesday Night

I don't mind using PowerShell, Python, Bat or anything else Windows has to offer. I'd rather not download a 3rd party tool but would consider it if it's needed

software is fun
  • 7,286
  • 18
  • 71
  • 129

2 Answers2

1

you can read the files with "os" in python and replace the name with a regular expresion:

Read files: https://www.tutorialspoint.com/python/os_rename.htm

Rename files with python: Rename multiple files in a directory in Python

Use regex to delete text : How to remove symbols from a string with Python?

0

You can use a single PowerShell cmdlet:

Get-ChildItem *.mkv | Rename-Item -NewName { $_.name -Replace '.*?(\d{3}.*?)\[.*?\.','$1.'}
iz_
  • 15,923
  • 3
  • 25
  • 40
  • If you'd like to check the output before going through with this add -WhatIf at the end of the Rename-Item cmdlet: `Get-ChildItem *.mkv | Rename-Item -NewName { $_.name -Replace '.*?(\d{3} Clip \d).*?\.','$1.'} -WhatIf` – Persistent13 Jan 18 '19 at 03:05
  • Thanks but the Clip 1, Clip 2 were the names of the actual track. It's literally not called Clip X. I need to remove the square brackets and extra white spaces before and after the 00N Clip 1 – software is fun Jan 18 '19 at 17:07
  • @softwareisfun Can you add some more examples to your question? It's still pretty unclear right now, because `Folder Name - ` doesn't look like whitespace to me. – iz_ Jan 18 '19 at 23:29
  • @softwareisfun Updated my regex. – iz_ Jan 19 '19 at 19:44
  • Do i need to save the script in the same directory as the files? – software is fun Feb 08 '19 at 04:06
  • @softwareisfun You can save it if you like, but yes, it does have to be in the same directory. – iz_ Feb 08 '19 at 05:18