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
|
string CreateDirectory(string DirectoryPath, bool EndsWithBackslash)
{
while (DirectoryPath.EndsWith("\\"))
DirectoryPath = DirectoryPath.Remove(DirectoryPath.Length-1);
if (!Directory.Exists(DirectoryPath))
{
Directory.CreateDirectory(DirectoryPath);
}
else
{
int indexBracket1 = DirectoryPath.IndexOf("(");
int indexBracket2;
string Number = string.Empty;
if (indexBracket1 > -1)
{
indexBracket2 = DirectoryPath.IndexOf(")", indexBracket1);
Number = DirectoryPath.Substring(indexBracket1 + 1, indexBracket2 - indexBracket1 - 1);
}
if (indexBracket1 < 0)
{
DirectoryPath = DirectoryPath + "(2)";
DirectoryPath = CreateDirectory(DirectoryPath, EndsWithBackslash);
}
else
{
DirectoryPath = DirectoryPath.Replace("(" + Number + ")", "(" + (Convert.ToInt64(Number) + 1) + ")");
DirectoryPath = CreateDirectory(DirectoryPath, EndsWithBackslash);
}
}
if (EndsWithBackslash && !DirectoryPath.EndsWith("\\"))
DirectoryPath += @"\";
return DirectoryPath;
}
void CreateDirectory(ref string DirectoryPath, bool EndsWithBackslash)
{
DirectoryPath = CreateDirectory(DirectoryPath, EndsWithBackslash);
}
|