How to remove dots between words in file name?

Bulk Rename Utility How-To's

Re: How to remove dots between words in file name?

Postby RegexNinja » Mon May 25, 2020 4:10 am

Trm2
Sorry, I didnt catch your post till just now..
Most people dont wanna touch file-extensions, so for clarity, I omit them from examples.
You can always assume an invisible .ext (or DirName) for any of the posted OrigNames.

Is there still time for getting more javascript into the manual??
I saw the other post with Michael, and have some info that might clear things up.
Will try to post there soon.. Cheers!
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: How to remove dots between words in file name?

Postby Jakov » Mon May 25, 2020 8:52 am

RegexNinja

x64/x86 Its mostly at the end of file name but not always
The most favorite option for me is convert it to underscore ( v3.1.4_x64)
The previous code is just remove dots before (x86,x64) and not replace it with underscore for some file names
here some examples you can apply on it

Nitro.Pro.13.15.1.282.Ent.x64
PDF Architect 7.1.14.4969.x64
PDF.Desktop.6.0.8.x64
Nuance_PowerPDF_Advanced_3.00.6439_x64

Dear RegexNinja
I want to remove dots anywhere (between word and word + between word and number ) but not between numbers
In conclusion, remove dots anywhere and do not touch dots between numbers of file version.

Thanks
Jakov
 
Posts: 55
Joined: Sat May 23, 2020 1:29 am

Re: How to remove dots between words in file name?

Postby RegexNinja » Mon May 25, 2020 11:36 am

Ok, here's the latest...
Line1 looks for the last x64/x86.. If there's a space, -, or . in front of it, it gets converted to _x64/_x86
If you think of anything else in front that should get converted, just post back with examples.
Lines 2/3 convert . ---> Space like you said in the last post.
Line4 converts 1-or-more-spaces ---> 1-space.

Thanks for examples.. Makes it much easier.. Hopefully, you still have plenty of names for testing.
Please give it a good preview, because this replaces all dots not inbetween numbers.

a = name.replace(/^(.*)[-\. ](x64|x86)(.*)$/,'$1_$2$3')
b = a.replace(/([^\d])\.+/g, '$1 ')
c = b.replace(/\.+([^\d])/g, ' $1')
newName = c.replace(/ +/g, ' ')


Results like:
Any . . . . . Name ------------------> Any Name
12.34.abc.56.78 -------------------> 12.34 abc 56.78
202005190-x64.1234 --------------> 202005190_x64.1234
20200519022023 x86 --------------> 20200519022023_x86
Nitro.Pro.13.15.1.282.Ent.x64 ---> Nitro Pro 13.15.1.282 Ent_x64
PDF Architect 7.1.14.4969.x64 ---> PDF Architect 7.1.14.4969_x64
SomeName.v1.2.3.x86.567 ------> SomeName v1.2.3_x86.567
SomeName2.v1.23-x64.567 ------> SomeName2 v1.23_x64.567

If its not what you're looking for, please post back with some more examples..
Cheers!
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: How to remove dots between words in file name?

Postby trm2 » Mon May 25, 2020 9:40 pm

It's not that you are not providing the code, the poster keeps changing the pattern.

New pattern not matched.

Nuance_PowerPDF_Advanced_3.00.6439_x64

Poster, please realize that if you have different patterns

1. Post all of the patterns so RegexNinja can see them all at once and make a determination.
2. Realize that not all patterns can be satisfied at one time. It may take different scripts or RegEx to accomplish what you want.
3. You are doing fine as far as providing samples but again, the patterns are changing whether you realize it or not.
4. Always best to present all samples as FROM TO to simplify things for us. That way it eliminates a lot of back and forth guess work.

Thanks for your understanding in this matter.

And again I have stressed this in other posts - I wish admin would post this as part of the posting rules - although how many people read them is another question entirely.
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm

Re: How to remove dots between words in file name?

Postby Jakov » Tue May 26, 2020 8:02 am

RegexNinja

Million Thanks
Its amazing code
Thanks for your effort and times
I can not thank you enough
May God protect you everywhere
Thanks you my bro
Best Regards
Jakov
 
Posts: 55
Joined: Sat May 23, 2020 1:29 am

Re: How to remove dots between words in file name?

Postby Jakov » Tue May 26, 2020 8:10 am

trm2

Iam so so sorry my bro
Please be patient for me
The pattern you are talking about it (Nuance_PowerPDF_Advanced_3.00.6439_x64)
Its instead of dots, there are underscore so I will take the idea of code and I can edit the code to look for underscore instead of dots and the code work in same way.

In conclusion, I made mistake by posting such pattern so forgive me please.
Thanks for any explanation
Best Regards
Jakov
 
Posts: 55
Joined: Sat May 23, 2020 1:29 am

Re: How to remove dots between words in file name?

Postby RegexNinja » Tue May 26, 2020 11:59 am

Jakov
To be honest, I didnt consider that you also wanted to replace underscores.
I completely missed that example.. Here's something you might wanna try.

Line1 looks for the last x64 or x86.. If there's a space, -, or . in front of it,
It temporarily gets converted to |x64 or |x86 (so nothing touches it till Line6)
Lines2/3 convert 1-or-more . into 1-space (unless inbetween numbers)
Line4 converts 1-or-more underscores into 1-space
Line5 converts 1-or-more spaces into 1-space
Line6 converts |x64 or |x86 back into _x64 or _x86

a = name.replace(/^(.*)[-_\. ](x64|x86)(.*)$/,'$1|$2$3')
b = a.replace(/([^\d])[\.]+/g, '$1 ')
c = b.replace(/[\.]+([^\d])/g, ' $1')
d = c.replace(/_+/g,' ')
e = d.replace(/ +/g, ' ')
newName = e.replace('|','_')


Results:
12.34.abc.56.78 -----------------------------------> 12.34 abc 56.78
202005190-x64.1234 ------------------------------> 202005190_x64.1234
20200519022023 x64 ------------------------------> 20200519022023_x64
20200519022023.x64 ------------------------------> 20200519022023_x64
Any . _ . _ . Name ---------------------------------> Any Name
Driver.Booster.Repack.7.4.0.730 -----------------> Driver Booster Repack 7.4.0.730
firefox.2020-01-08_065639 ----------------------> firefox 2020-01-08 065639
Home.Photostudio.Repack.v16 -------------------> Home Photostudio Repack v16
Movavi..Photo__Editor..Repack_.._v4.4.0 ------> Movavi Photo Editor Repack v4.4.0
Nitro.Pro.13.15.1.282.Ent.x64 -------------------> Nitro Pro 13.15.1.282 Ent_x64
Nuance_PowerPDF_Advanced_3.00.6439_x64 --> Nuance PowerPDF Advanced 3.00.6439_x64
PDF.Desktop.6.0.8.x64 ----------------------------> PDF Desktop 6.0.8_x64
PDF_Architect....7.1.14.4969.x64 ---------------> PDF Architect 7.1.14.4969_x64

Note how the underscore is replaced in the firefox file.
If you'd rather treat underscore just like dots (keep them when inbetween numbers), use this instead:

Line1 looks for the last x64 or x86.. If there's a space, -, or . in front of it,
It temporarily gets converted to |x64 or |x86 (so nothing touches it till Line5)
Lines 2/3 convert 1-or-more . and/or _ into 1-space (unless inbetween numbers)
Line4 converts 1-or-more spaces into 1-space
Line5 converts |x64 or |x86 back into _x64 or _x86

a = name.replace(/^(.*)[-_\. ](x64|x86)(.*)$/,'$1|$2$3')
b = a.replace(/([^\d])[\._]+/g, '$1 ')
c = b.replace(/[\._]+([^\d])/g, ' $1')
d = c.replace(/ +/g, ' ')
newName = d.replace('|','_')


The results are identical as above samples, except the firefox file keeps the underscore.
Cheers.
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: How to remove dots between words in file name?

Postby Jakov » Wed May 27, 2020 10:49 am

Oh! RegexNinja

Billion Thanks
Its so amazing code
I appreciate your effort and times

Please RegexNinja, I have got the idea of the code so if any other pattern available I will add it to the code by myself.
So feel free to take your time.

Finally, which is the best source to learn such codes in order to develop my self.

Best Regards
Jakov
 
Posts: 55
Joined: Sat May 23, 2020 1:29 am

Re: How to remove dots between words in file name?

Postby trm2 » Wed May 27, 2020 11:46 am

The Best source is the RegEx manual in the Appendix of Volume I - didn't you download it yet?

This will be followed up shortly (hopefully) by Volume II which not only discusses many of the examples found here,
but provides full analysis. there is also a RegEx Manual Vol II in that appendix as well. But for now, plenty of information
can be found in Volume I's appendix. Download it today.
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm

Re: How to remove dots between words in file name?

Postby RegexNinja » Thu May 28, 2020 10:47 am

Jakov
Trm2 is correct, I've learned some things from that regex-section myself..
You might have figured it out already, but the regex-syntax for javascript's .replace() is:
.replace(/__RegexMatch__/modifiers, '__Replace__')

The underscores are thrown-in just for clarity..
Modifiers need not exist, but can be things like g(global/all), i(case-insensitive), or gi(for both).
Expressions within RegexMatch are where the manual really comes in handy..

Basically though, you just (group) any text that you wanna keep..
If you specify anything that's not within a (group), it means you wanna lose it.

Line1: a = name.replace(/^(.*)[-_\. ](x64|x86)(.*)$/, '$1|$2$3')
Sets the variable called 'a' to hold the results of what happens to OrigName after the replacement.
Match: Beginning(text) until the last [either: -_. ](x64-or-x86) and then (anything-else) until end-of-name.
The $#'s in Replace reference the (groups) in RegexMatch that you wanna keep..
If you decide to add any chars within the set: [-_\. ], make sure that its after the -

The - is a special-character when its in a [set], unless its the 1st-character.
This lets you use things like [a-f] to represent either: a, b, c, d, e or f.
You could improve yours with [-_\. ]+ to fix names like: "AnyName.v123_-- _ --._.x86" if its an issue.

As you've prob noticed, there's other special-chars like . that must be spec'd like \.
Otherwise . will mean: any-character whatsoever!

Line2: b = a.replace(/([^\d])[\._]+/g, '$1 ')
Sets the variable 'b' to hold the results of what happens to a after the replacement.
Group1 matches one: NonNumber, followed by [any:._] 1-or-more times, g=global(all) to replace all-occurences.
This entire-match get replaced by $1Space, (where $1 represents the NonNumber matched by Group1).

With javascript's .replace, since nothing else was matched, nothing else gets touched.
That's different than how #1Regex works (you must match everything that you wanna keep).
Best way to learn, I think, is taking examples from the manual/etc, and trying them out in BRU.

For javascript, I use places like: https://eloquentjavascript.net to grab the syntax.
Then I come back into BRU's javascript to try out different things against my names.
I dont learn well from reading, so I usually have to experiment until it sinks in.

But dont try it till you look at the manual.. At least learn a few varNames like name, counter, etc.
I made that mistake myself, and it just ended up holding me back.
Hope it helps with any future editing.. Cheers!
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: How to remove dots between words in file name?

Postby Jakov » Mon Jun 01, 2020 8:39 pm

Thanks for Trm2

and billion thanks for you (RegexNinja)
Finally. Thank you for guiding me.
Best Regards
Jakov
 
Posts: 55
Joined: Sat May 23, 2020 1:29 am

Re: How to remove dots between words in file name?

Postby Keith12345 » Sun Jun 19, 2022 7:41 pm

@echo off
setlocal enabledelayedexpansion
for /f "usebackq delims=" %%N in (`dir /s /b`) do (
set var=%%~nN
set var=!var:^.= !
set var=!var:%%= !
if not "!var!"=="%%~nN" (
if not exist "%%~dpN!var!%%~xN" (
echo "%%N" --^> "!var!%%~xN"
ren "%%N" "!var!%%~xN"
) else (
echo File "!var!%%~xN" ^(from %%N^) already exists.
)
)
)
INFORMATION
- Just save this code into a file on a Windows PC, and give it the name RemovePeriods.bat
- USE: I prefer to move several video files into a single folder, then run the command.
- Copy RemovePeriods.bat into the folder which contains the video files, or any files.
- Double click on RemovePeriods to execute it.
- Within 2 seconds, you will see extra periods have been replaced with a space. Also, if the file contains lots of periods in a row, e.g., my......first...........and..last.words.mpg or .avi or any other file extension, you can click to re-run the command over and over to remove all of them.
- THIS DOES NOT REMOVE THE PERIOD BEFORE THE FILES EXTENSION.
Keith12345
 
Posts: 1
Joined: Sun Jun 19, 2022 7:31 pm

Previous

Return to How-To