1

I have a list of files in this format NameSerie.S0E1.randomcharacters.mkv where i want to remove the randomcharacters to get NameSerie.S0E1.mkv

I have the following but for this i need to know the randomcharacters which sadly are random.

#rename files
Get-ChildItem $Location | Rename-Item -NewName {$_.Name.Replace("[480p]","") }

Does someone have an idea?

3
  • Does this answer your question? PowerShell to remove text from a string Commented Feb 16, 2020 at 9:05
  • Please define (in the question) what is recognizable in your string rather than what is not. Presumably the extension is always .mkv (or not???), are the dots always on the same place? Is there always a S#E# format in front of the random characters? etc. Commented Feb 16, 2020 at 9:30
  • the .mkv is always there and the rest is always formated like this. Commented Feb 16, 2020 at 9:44

2 Answers 2

1

You could use

(.*?)[^.]+\.([^.]+)$

And replace this with

$1$2

See a demo on regex101.com.
Alternatively, you could split on the dot and glue the array back together programatically.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is it! Thanks for the link, I was looking for a website like this!!!
0

Try this:

#rename files
Get-ChildItem $Location | Rename-Item -NewName {$_.Name.Split(".")[0..1] -join ".$($_.Name.Split(".")[3])" }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.