Page 1 of 1

Remove space at end of filenames?

Posted: 07 Jul 2015 01:55
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, "  / ";

Re: Remove space at end of filenames?

Posted: 07 Jul 2015 07:40
by bdeshi

Code: Select all

 rename 'r', '^\s*(.*?)\s*(\.[^\.]*)$ > $1$2';
this can remove both beginning and ending spaces in base name.

Re: Remove space at end of filenames?

Posted: 08 Jul 2015 00:11
by christopherwood
It works! Thank you so much!

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

Thanks!