Remove space at end of filenames?

Discuss and share scripts and script files...
Post Reply
christopherwood
Posts: 30
Joined: 07 Jul 2015 01:36

Remove space at end of filenames?

Post by christopherwood »

I have a rename script that does various S&R operations on whatever files are selected in the file list, usually multiple. But sometimes I end up with (or even start with) a space at the end of some of the filenames.

I wonder is there a way to search for a space and replace it with null, if the space occurs at the end of the filename?

[edit to add] I mean at the end of the filename, before the dot & extension: LIKE THIS .txt and what I hope for is LIKE THIS.txt

I really did search the forum and google a lot, but I have not found a way to do it. Help!?

Below just FYI is the script I am using ...

Code: Select all

#138; 
 #136; 
 #130; 
 rename s, " And / & ";
 rename s, ", & / & ";
 rename s, "——/—";
 rename s, " Aka / aka \";
 rename s, " Vs / vs \";
 rename s, "  / ";
 rename s, "  / ";
 rename s, "  / ";

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Remove space at end of filenames?

Post by bdeshi »

Code: Select all

 rename 'r', '^\s*(.*?)\s*(\.[^\.]*)$ > $1$2';
this can remove both beginning and ending spaces in base name.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

christopherwood
Posts: 30
Joined: 07 Jul 2015 01:36

Re: Remove space at end of filenames?

Post by christopherwood »

It works! Thank you so much!

Now if I can parse that syntax maybe I will actually learn something.

Thanks!

Post Reply