-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileNameUtils.cs
32 lines (28 loc) · 1.02 KB
/
FileNameUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Text;
namespace Notpod
{
/// <summary>
/// Contains methods of handling file names.
/// </summary>
public class FileNameUtils
{
/// <summary>
/// Converts illegal characters in filename into an underscore character.
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename with illegal characters converted to underscore</returns>
public static string ConvertIllegalCharacters(string filename)
{
string[] illegal = new string[] { ":", "*", "?", "\"", "<", ">", "|", "/", "\0" };
string replaceWith = "_";
foreach (string ic in illegal)
filename = filename.Replace(ic, replaceWith);
filename = filename.Replace(".\\", "_\\");
filename = filename.Replace(",\\", "_\\");
filename = filename.Replace(" \\", "_\\");
return filename;
}
}
}