Remove part of a filename

A swapping-ground for Regular Expression syntax

Remove part of a filename

Postby magarlick » Tue May 17, 2016 6:40 pm

HI all

I am totally flummoxed by regex. No matter how much I try to understand it,I don't get it.

I have thousands of files which my backup software, ViceVersa, archived upon deletion. It rename them all from, eg

Sun DK.jpg_(2016-05-16_19-19-16_DEL_T).jpg

to Sun DK.jpg

As you can see, ViceVersa appends a timestamp after the file extension, in the format _(*).ORIGINALEXTENSION

So I need to delete everything from and including the _ after the file original file extension.

Hope this is clear. Another example:

Max.mxp_(2016-05-16_19-19-16_DEL_T).mxp need to change to Max.mpx

Kind regards.
magarlick
 
Posts: 1
Joined: Tue May 17, 2016 6:32 pm

Re: Remove part of a filename

Postby therube » Tue May 17, 2016 7:29 pm

(Assumes there is no _ in the wanted part of your filename, as the name will be truncated at the first _.
There's probably a cleaner way, with only REGEX, but I'd have to brush up some, so...)

1:Regex

Match: (.*?_)
Replace: \1

and

3:Replace

Replace: _
With:
(That's nothing in the With: box)

Or you could use Remove instead of Replace.

5:Remove

Chars: _
therube
 
Posts: 421
Joined: Mon Jan 18, 2016 6:23 pm

Re: Remove part of a filename

Postby therube » Tue May 17, 2016 7:42 pm

There's probably a cleaner way, with only REGEX

This:


1:Regex

Match: (.*?)_
Replace: \1
therube
 
Posts: 421
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions


cron