24 lines
526 B
C#
Raw Permalink Normal View History

2022-04-10 03:38:39 +03:00
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace YoutubeDownloader.Core.Utils;
2023-07-12 17:22:13 +03:00
public static class PathEx
2022-04-10 03:38:39 +03:00
{
private static readonly HashSet<char> InvalidFileNameChars =
[
2024-09-01 23:25:50 +03:00
.. Path.GetInvalidFileNameChars(),
];
2022-04-10 03:38:39 +03:00
public static string EscapeFileName(string path)
{
var buffer = new StringBuilder(path.Length);
foreach (var c in path)
buffer.Append(!InvalidFileNameChars.Contains(c) ? c : '_');
return buffer.ToString();
}
2023-10-21 17:58:59 +03:00
}