forked from SharpRepository/SharpRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelativePath.cs
More file actions
80 lines (69 loc) · 1.83 KB
/
RelativePath.cs
File metadata and controls
80 lines (69 loc) · 1.83 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
77
78
79
80
using System;
using System.IO;
namespace SharpRepository.Tests
{
//TODO: BG - This guts of the following code was found online. Find the source and reference.
public class RelativeDirectory
{
private DirectoryInfo _dirInfo;
public RelativeDirectory()
{
_dirInfo = new DirectoryInfo(Environment.CurrentDirectory);
}
public RelativeDirectory(string absoluteDir)
{
_dirInfo = new DirectoryInfo(absoluteDir);
}
public string Dir
{
get { return _dirInfo.Name; }
}
public string Path
{
get { return _dirInfo.FullName; }
set
{
try
{
var newDir = new DirectoryInfo(value);
_dirInfo = newDir;
}
catch
{
// silent
}
}
}
public Boolean UpTo(string folderName)
{
do
{
if (_dirInfo.Name.Equals(folderName)) return true;
} while (Up());
return false;
}
public Boolean Up(int numLevels)
{
for (int i = 0; i < numLevels; i++)
{
DirectoryInfo tempDir = _dirInfo.Parent;
if (tempDir != null)
_dirInfo = tempDir;
else
return false;
}
return true;
}
public Boolean Up()
{
return Up(1);
}
public Boolean Down(string match)
{
DirectoryInfo[] dirs = _dirInfo.GetDirectories(match + '*');
if (dirs.Length == 0) return false;
_dirInfo = dirs[0];
return true;
}
}
}