forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPaths.cs
More file actions
76 lines (76 loc) · 1.62 KB
/
Copy pathPaths.cs
File metadata and controls
76 lines (76 loc) · 1.62 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.IO;
namespace UnityEditor.Utils
{
internal static class Paths
{
public static string Combine(params string[] components)
{
if (components.Length < 1)
{
throw new ArgumentException("At least one component must be provided!");
}
string text = components[0];
for (int i = 1; i < components.Length; i++)
{
text = Path.Combine(text, components[i]);
}
return text;
}
public static string[] Split(string path)
{
List<string> list = new List<string>(path.Split(new char[]
{
Path.DirectorySeparatorChar
}));
int i = 0;
while (i < list.Count)
{
list[i] = list[i].Trim();
if (list[i].Equals(string.Empty))
{
list.RemoveAt(i);
}
else
{
i++;
}
}
return list.ToArray();
}
public static string GetFileOrFolderName(string path)
{
string result;
if (File.Exists(path))
{
result = Path.GetFileName(path);
}
else
{
if (!Directory.Exists(path))
{
throw new ArgumentException("Target '" + path + "' does not exist.");
}
string[] array = Paths.Split(path);
result = array[array.Length - 1];
}
return result;
}
public static string CreateTempDirectory()
{
string tempFileName = Path.GetTempFileName();
File.Delete(tempFileName);
Directory.CreateDirectory(tempFileName);
return tempFileName;
}
public static string NormalizePath(this string path)
{
if (Path.DirectorySeparatorChar == '\\')
{
return path.Replace('/', Path.DirectorySeparatorChar);
}
return path.Replace('\\', Path.DirectorySeparatorChar);
}
}
}