-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPathHelper.cs
More file actions
57 lines (46 loc) · 1.59 KB
/
Copy pathPathHelper.cs
File metadata and controls
57 lines (46 loc) · 1.59 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Components
{
public static class PathHelper
{
public static string GetEntryDirectory()
{
return new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName;
}
public static string GetEntryPath(params string[] paths)
{
return Path.Combine(new[] { GetEntryDirectory() }.Concat(paths).ToArray());
}
public static string GetExecutingDirectory()
{
return Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
}
public static string GetExecutingPath(params string[] paths)
{
return Path.Combine(new[] { Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) }.Concat(paths).ToArray());
}
public static string SanitizePath(string name, char c)
{
Path.GetInvalidPathChars().Iter(x => name = name.Replace(x, c));
return name.Replace(':', c).Replace('\\', c).Replace('/', c);
}
public static string SanitizeName(string name, char c)
{
Path.GetInvalidFileNameChars().Iter(x => name = name.Replace(x, c));
return name;
}
public static string SanitizeName(string name)
{
return SanitizeName(name, '_');
}
public static string SanitizePath(string name)
{
return SanitizePath(name, '_');
}
}
}