Trims trailing spaces and dots when escaping file name instead of replacing them.

This commit is contained in:
2022-11-17 12:00:33 +08:00
parent 05124ac406
commit d89e5a2e68

View File

@@ -40,7 +40,9 @@ namespace Cryville.Common {
/// <param name="name">The file name excluding the extension.</param>
/// <returns>The escaped file name.</returns>
public static string EscapeFileName(string name) {
return Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}\.\s]", "_");
var result = Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}]", "_").TrimEnd(' ', '.');
if (result.Length == 0) return "_";
return result;
}
}
}