Ejemplo n.º 1
0
        public static string CleanFolderName(string name, bool replace = true, ColonReplacementFormat colonReplacement = ColonReplacementFormat.Delete)
        {
            name = FileNameCleanupRegex.Replace(name, match => match.Captures[0].Value[0].ToString());
            name = name.Trim(' ', '.');

            return(CleanFileName(name, replace, colonReplacement));
        }
Ejemplo n.º 2
0
        public static string CleanFileName(string name, bool replace = true, ColonReplacementFormat colonReplacement = ColonReplacementFormat.Delete)
        {
            var colonReplacementFormat = colonReplacement.GetFormatString();

            string result = name;

            string[] badCharacters  = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
            string[] goodCharacters = { "+", "+", "", "", "!", "-", colonReplacementFormat, "", "" };

            for (int i = 0; i < badCharacters.Length; i++)
            {
                result = result.Replace(badCharacters[i], replace ? goodCharacters[i] : string.Empty);
            }

            return(result.Trim());
        }
Ejemplo n.º 3
0
        public static String GetFormatString(this ColonReplacementFormat format)
        {
            switch (format)
            {
            case ColonReplacementFormat.Delete:
                return("");

            case ColonReplacementFormat.Dash:
                return("-");

            case ColonReplacementFormat.SpaceDash:
                return(" -");

            case ColonReplacementFormat.SpaceDashSpace:
                return(" - ");

            default:
                return("");
            }
        }