Multi Rename Tool : Remove some spaces only

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
tcmdus3r
Junior Member
Junior Member
Posts: 2
Joined: 2019-01-03, 17:27 UTC

Multi Rename Tool : Remove some spaces only

Post by *tcmdus3r »

Hi there,

I'd like to remove some spaces in my filenames but not all of them.

here's what i have :
  • Dummy Band Name Whatever_Dummy Song Title.flac
and what i would like to have :
  • DUMMYBANDNAMEWHATEVER_Dummy Song Title.flac
So basically, the rule is to remove any spaces located before the underscore (but to keep all other spaces after the underscore)
Oh, and i also want to capitalize all characters before the undescore btw.

The closest result i got so far was using RegEx with :

Search : ( )(.*)_(.*)
Replace With : \U$2_\n$3

But of course, this only removes the first space. Plus it neither capitalize the 1st group. Here's the result :
  • DummyBAND NAME WHATEVER_Dummy Song Title.flac
I've been searching through Total Commander help and been testing many things, but with no go so far.
And i have no idea how to tell the MRT to remove not only the first but all non-continuous spaces before my underscore.

I tried to test and play with this part of the help... :
Backreferences

\n Finds subexpression n another time in the search result.
Example: (.+)\1+ finds e.g. abab (where the first ab is found by .+ and the second by \1+ )
... but i really don't get how this is supposed to work, and maybe this doesn't apply for what i want to do at all ?


Last remark, i'd really like to achieve this through 1 pass only.


Thanks a lot for for your help.
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Multi Rename Tool : Remove some spaces only

Post by *Ovg »

I may be wrong, but I think this can be done only via script due to limited TC regex engine.
If you are still interested - I can write such AHK script.
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
User avatar
petermad
Power Member
Power Member
Posts: 14796
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Multi Rename Tool : Remove some spaces only

Post by *petermad »

To tcmdus3r
I cannot think of doing it with Regex, but I can do if with several consecutive runs of the Multi Rename Tool (MRT). One of the tricks I use, is to temporarily make the part of the filename after the _ the file extension.

I have made an example for you where I have put some periods in the filename, in case that should be the case for some of your files. So the filename I use is "Dummy Band. Name Whatever_Dummy. Song Title.flac".

Between each step you have to close the MRT, re-select all files and re-open the MRT

1. First I replace all periods in the filename with a character that will not be part of any of the existing file names for example § - notice that the [E] option under Search & Replace is NOT selected: http://madsenworld.dk/tcmd/renamesongs1.png

2. Then I replace the extension period with another unique character for example ¤ - notice that I now select the [E] option under Search & Replace: http://madsenworld.dk/tcmd/renamesongs2.png

3. Now I replace the _ with a period. - notice that the 1x option under Search & Replace is selected, to only replace the first _ in case there are more: http://madsenworld.dk/tcmd/renamesongs3.png

4. Then I convert the name part of the filename to all Uppercase with the Rename mask: [U][N][n] - and at the same time I remove all spaces in the filename by entering a space in the "Search for:" field and <Clear> in the "Replace with:" field - the [E] option under Search & Replace must NOT be selected: http://madsenworld.dk/tcmd/renamesongs4.png

5. Then I replace the extension period with an _ again - Now the [E] option under Search & Replace HAS to be selected again: http://madsenworld.dk/tcmd/renamesongs5.png

6. Then I replace the § with . : http://madsenworld.dk/tcmd/renamesongs6.png

7. And finally I replace the ¤ with a . to re-enable the extension: http://madsenworld.dk/tcmd/renamesongs7.png

If you are sure that there is only one extension period in all filenames you can omit step 1 and 6.

.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Re: Multi Rename Tool : Remove some spaces only

Post by *milo1012 »

It's actually possible in TC's limited RegEx engine, but it gets really ugly:

Search for:

Code: Select all

(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?([^_\s]+_)(.+)
Replace with:

Code: Select all

$2$4$6$8$10$12$14$15$16
This will work for up to 8 "words" before the underscore. If you're expecting even longer constructs before the underscore, just repeat the pattern and expand the replacement string with

Code: Select all

$2$4$6$8$10$12$14$16$17$18
and so on.

There's probably some room for optimization of the pattern.
TC plugins: PCREsearch and RegXtract
User avatar
petermad
Power Member
Power Member
Posts: 14796
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Multi Rename Tool : Remove some spaces only

Post by *petermad »

2milo1012
Hmm - that doesn't seem to fully work: http://madsenworld.dk/tcmd/renamesongs_milo.png

The underscore and "Whatewer" is removed, and the first part of the name is not in Uppercase,
so:
"Dummy Band Name Whatever_Dummy Song Title.flac"
becomes:
"DummyBandNameDummy Song Title.flac"
in stead of:
DUMMYBANDNAMEWHATEVER_Dummy Song Title.flac"
Last edited by petermad on 2019-01-06, 14:20 UTC, edited 1 time in total.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Re: Multi Rename Tool : Remove some spaces only

Post by *milo1012 »

petermad wrote: 2019-01-06, 14:08 UTCJmm - it doesn't seem to fully work: http://madsenworld.dk/tcmd/renamesongs_milo.png
Seems that you mixed my 2nd replacement string with the original pattern. Also I didn't implement the uppercase conversion yet (which only works with TC 9.10 or newer).

This works for me with uppercase conversion:
Search for:

Code: Select all

(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?(([^_\s]+)\s)?([^_\s]+_)(.+)
Replace with:

Code: Select all

\U$2$4$6$8$10$12$14$15\n$16
Last edited by milo1012 on 2019-01-06, 14:29 UTC, edited 1 time in total.
TC plugins: PCREsearch and RegXtract
User avatar
petermad
Power Member
Power Member
Posts: 14796
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Multi Rename Tool : Remove some spaces only

Post by *petermad »

2milo1012
You are right - I used $2$4$6$8$10$12$14$16$17$18 in stead of $2$4$6$8$10$12$14$15$16 - sorry :oops: .
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
tcmdus3r
Junior Member
Junior Member
Posts: 2
Joined: 2019-01-03, 17:27 UTC

Re: Multi Rename Tool : Remove some spaces only

Post by *tcmdus3r »

Thanks to everyone who replied for your help, and especially to milo1012.

Your last version works like a charm so far (including the capitals) :D

And it might be 'ugly' anyhow, but i don't really care, as it produces my desired result, which is the most important to me at the end :wink:

It definitely helped me, so many thanks again for your time :mrgreen:
Post Reply