Using RegEx to replace invalid characters
Posted
by yeahumok
on Stack Overflow
See other posts from Stack Overflow
or by yeahumok
Published on 2010-06-09T19:38:14Z
Indexed on
2010/06/09
19:42 UTC
Read the original article
Hit count: 608
Hello
I have a directory with lots of folders, subfolder and all with files in them. The idea of my project is to recurse through the entire directory, gather up all the names of the files and replace invalid characters (invalid for a SharePoint migration).
However, i'm completely unfamiliar with Regular Expressions. The characters i need to get rid in filenames are: ~, #, %, &, *, { } , \, /, :, <>, ?, -, | and "" I want to replace these characters with a blank space. I was hoping to use a string.replace() method to look through all these file names and do the replacement.
So far, the only code i've gotten to is the recursion. I was thinking of the recursion scanning the drive, fetching the names of these files and putting them in a List.
Can anybody help me with how to find/replace invalid chars with RegEx with those specific characters?
© Stack Overflow or respective owner