removing illegal characters

Advanced Renamer forum
#1 : 13/02-19 04:41
Gary Storm
Gary Storm
Posts: 2
I have about 3,000 files on a drive, to check for illegal characters, before copying across to SharePoint. The person who created the files used % and # sometimes, amongst others.

I've used a test file (.txt), and named it "test-#-%-&-removal" .

Using the 'Remove Pattern' method.

Pattern: \*\?\%\#\&\+\

Start Batch, and the result is that it removes ALL text from the filename, and I'm left with just ".txt".

Obviously I'm doing something wrong. Advice appreciated.

It would be nice to have a preview option, so if I drag in a parent folder, the application could give a before/after view of the filenames, so I could make sure it was just removing illegal characters, not the whole filename, or I could see files which had other illegal characters I could then add to the pattern.





13/02-19 04:41
#2 : 13/02-19 10:07
David Lee
David Lee
Posts: 1125
The problem is that * is being interpreted as a wildcard and will match any string of characters.

You can work around the problem by entering the characters as a Regular Expression:
\*|\?|%|#|&|\+

Here "|" represents OR and "\" is the "escape" character that forces RegEx metacharacters to represent themselves.

However the characters " * : < > ? / \ | are not allowed in Windows filenames and so shouldn't be present in your filenames and, according to MSoft, these are the only characters that are invalid on SharePoint Online.

However the additional characters ~ # % & { } . are not allowed on SharePoint Server 2013. If this is your problem then the plain text string ~\#\%\&\{\}\. should remove all rogue characters.

Note that \ is a separator character (when not part of a Regular Expression) so is not required at the start and end of the string.




13/02-19 10:07
#3 : 14/02-19 06:40
Gary Storm
Gary Storm
Posts: 2
Reply to #2:

Thanks David, works perfectly!

Yes, SharePoint 2013, with %, # and & in the filenames (naughty!). Also some filenames so many sub-folders down that they exceed the 253 character limit (which I used to think was 256, but anyway).

Also, I realised once it had the new pattern in, that it gives a preview of the amended filename, so that comment also answered.

Cheers!


14/02-19 06:40