Using RegEx to replace invalid characters

I have a directory with lots of folders, sub-folder 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<string>.

Can anybody help me with how to find/replace invalid chars with RegEx with those specific characters?

Read more here: Source link