Removing whitespace at the end of folder names

A swapping-ground for Regular Expression syntax

Removing whitespace at the end of folder names

Postby ctap » Wed May 28, 2014 4:17 pm

Any idea how to you remove a trailing space from the end of the complex folder name?

I have googled around regular expression for a while and it is borderline terrifying :)


I have about 10,000 folders on our NAS that some MAC user (fired) typed spaces at the end of the filename... like "Client Number 8 - Bob JOhnson! "

The space at the end of the folder name is messing with some of our software

any help on how to do this is bulk would be greatly appreciated
ctap
 
Posts: 1
Joined: Wed May 28, 2014 4:12 pm

Re: Removing whitespace at the end of folder names

Postby truth » Mon Jun 09, 2014 11:40 am

Microsoft's win32 api auto-removes trailing spaces before supplying BRU with name.
(leaving BRU/most-other-apps no way to match/remove final spaces)

You may want to try long path tool, since it works independantly of the win32 api.
Another option is using another shell, if you're comfortable with any of them.

IF Dir will return final-spaces, you could use sed to quickly handle it:
Dir/ad/b/s|sed -n -r "s/(.*\\)(.*[^\t ])([ \t]{1,})$/ren \x22\\\\\.\\&\x22 \x22\2\x22/p"|sed e
It would remove trailing spaces/tabs from DirNames by using UNC paths.
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay


Return to Regular Expressions