Last active
August 29, 2015 14:23
-
-
Save JeffreyMFarley/dbad21c250103bce426f to your computer and use it in GitHub Desktop.
Remove Bad File Name Characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static public string RemoveBadFileNameChars(this string strFileName) | |
{ | |
char[] badPath = Path.GetInvalidPathChars(); | |
char[] badFile = { '\\', '/', ':', '*', '?', '\"', '<', '>', '|', '' }; | |
foreach (char c in badPath) | |
strFileName = strFileName.Replace(c, '_'); | |
foreach (char c in badFile) | |
strFileName = strFileName.Replace(c, '_'); | |
strFileName = strFileName.Replace("\0", ""); | |
return strFileName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment