Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Discuss and share scripts and script files...
shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

Suggest me a working script to shrink multi spaces to single and also replacing unwanted characters + avoid name collisions when two or more files get the same name after renaming by ADDING= SINGLESPACE 3 DIGIT RANDOM NUMBER as suffix

before=New - ( ) ... -`text @@@-file.txt

after(not what i want)=NewLOTSOFSPACESTextLOTSOFSPACESFile.txt

(what i want)=New Text File.txt

i am currently using===>
::rename s, "~-()[]{}….@,` ;> "; #139; #126; #113;




where u already know=
#139
File / Rename Special / Remove Diacritics
#126
File / Rename Special / Aaa Aa.aaa
#113
File / To Clipboard / Item Base(s) Shift+F

i am using=XYplorer 27.00.0800
Last edited by shuklaharshit75 on 12 Jul 2025 01:34, edited 1 time in total.

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming using script.(or any simpler method)

Post by jupe »

After someone takes the time to answer your query will you just abandon the topic again though?

viewtopic.php?p=230577#p230577

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

reply to jupe=rename s, "-._[]()@%`*~> "; rename r, "\s+ > "; rename r, "\s+(\.[^.]+?$|$) > $1"; #139; #126; #113;

works perfectly. Love u, sorry for my mistakes.


can u please provide a way to avoid name collisions when two or more files get the same name after renaming by ADDING= SINGLESPACE 3 DIGIT RANDOM NUMBER as suffix.

like ABCD.txt and ABCD 5698.txt (when two or more files get the same name after renaming)

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by jupe »

Instead of relying on chatgpt, I'd recommend you refer to the help file for the rename cmd that you are using, because there it shows that it accepts flags, so you could avoid collisions with flag 8, eg

rename s, "-._[]()@%`*~> ", , , 8;

you'd need to add it per rename cmd, you can modify the suffix style used here

Configuration | Colors and Styles | Templates | Filename Affixes | Incremental affix

If you want 3 digit random number instead of incr suffix, you could try using
 <date fff>
in the above input box, if this method isn't acceptable it is possible to do it in an alternate way but it would require much more scripting.

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

reply to jupe===> first part already works.
Animation.gif
Adjust the script so that avoid name collisions is fixed, when two or more files get the same name after renaming by ADDING= SINGLESPACE 3 DIGIT RANDOM NUMBER as suffix(to shrink multi spaces to single and also replacing unwanted characters )

currently this script is cleaning up names very well. but not avoiding name collisions and random suffix of 3 digits.

Code: Select all

rename s, "-._[]()@%`*~> "; rename r, "\s+ >  "; rename r, "\s+(\.[^.]+?$|$) > $1"; #139; #126; #113;
Screenshot 2025-07-12 081343.png
Screenshot 2025-07-12 081902.png
You do not have the required permissions to view the files attached to this post.

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by jupe »

Re read my last post carefully and look where I have added flag 8 in the first example (in the code block), then adapt that to the script I previously supplied that you are now using (shown in your last screenshot), ie. add flag 8 to all 3 rename cmds.

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

Code: Select all

rename s, "-._[]()@%`*~> ", , , 8;; rename r, "\s+ >  ", , , 8;; rename r, "\s+(\.[^.]+?$|$) > $1", , , 8; #139; #126; #113;
works perfectly, thanks.
aaaaa.gif

apart from avoid name collisions when two or more files get the same name after renaming by ADDING= SINGLESPACE 3 DIGIT RANDOM NUMBER as suffix.
You do not have the required permissions to view the files attached to this post.

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by jupe »

shuklaharshit75 wrote: 12 Jul 2025 05:44 works perfectly, thanks.
apart from avoid name collisions when two or more files get the same name after renaming by ADDING= SINGLESPACE 3 DIGIT RANDOM NUMBER as suffix.
I was hoping I would get a thanks eventually, thanks. No need for double semi-colons in the script.

So when you re-read my last post carefully, did you try my suggestion of putting the
 <date fff>
into the incr suffix template box in config, and that is not working?

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

u have been very helpful so thanks anyday.
I want a script method. <date fff> not this.

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by jupe »

I don't understand if you tried it or not, but anyway FYI the script you are currently using uses the config field so it should add a 3 digit random number suffix just as you requested.

2025-07-12_142411.png

But yes if you are not content with that method then a much larger script would need to be written that performs all your renames in one action I think.
You do not have the required permissions to view the files attached to this post.

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

Code: Select all

rename s, "-._[]()%,`*~> ", , , 8; rename r, "\s+ >  ", , , 8;; rename r, "\s+(\.[^.]+?$|$) > $1", , , 8; #139; #126; #113;
and <date fff> produces weird results.
there isnt any space bw File and 787. but other files do have proper spacing. No random number generated. only 787 is suffixed.


like see New Text File787 (1).txt
You do not have the required permissions to view the files attached to this post.

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by jupe »

Ok I understand now, you did try it, it's just that your computer is so fast that it is renaming multi files at the same 3 digit ms time, the space missing sometimes could probably be fixed by re-arranging the order of some of the rename cmds but not worth it, it was a bit of a hackjob workaround suggestion anyway since that field doesn't accept <get rs>, oh well, if I get time I might script it up for you properly instead of being lazy, or maybe some other forum user might.

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

your computer is so fast === i3 11 gen :D :biggrin: :kidding: :)

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by jupe »

yes, speed can be relative

shuklaharshit75
Posts: 42
Joined: 10 Aug 2024 10:12

Re: Unable to shrink multi spaces to single one while renaming and avoid name collisions using script

Post by shuklaharshit75 »

i am waiting. (((if I get time I might script it up for you properly instead of being lazy, or maybe some other forum user might.)))

Locked