forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystem.cs
More file actions
106 lines (86 loc) · 2.53 KB
/
FileSystem.cs
File metadata and controls
106 lines (86 loc) · 2.53 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.IO;
namespace ScriptCs
{
public class FileSystem : IFileSystem
{
public IEnumerable<string> EnumerateFiles(string dir, string searchPattern)
{
return Directory.EnumerateFiles(dir, searchPattern, SearchOption.AllDirectories);
}
public void Copy(string source, string dest, bool overwrite)
{
File.Copy(source, dest, overwrite);
}
public bool DirectoryExists(string path)
{
return Directory.Exists(path);
}
public void CreateDirectory(string path)
{
Directory.CreateDirectory(path);
}
public void DeleteDirectory(string path)
{
Directory.Delete(path, true);
}
public string ReadFile(string path)
{
return File.ReadAllText(path);
}
public string[] ReadFileLines(string path)
{
return File.ReadAllLines(path);
}
public bool IsPathRooted(string path)
{
return Path.IsPathRooted(path);
}
public string CurrentDirectory
{
get { return Environment.CurrentDirectory; }
}
public string NewLine
{
get { return Environment.NewLine; }
}
public DateTime GetLastWriteTime(string file)
{
return File.GetLastWriteTime(file);
}
public void Move(string source, string dest)
{
File.Move(source, dest);
}
public bool FileExists(string path)
{
return File.Exists(path);
}
public void FileDelete(string path)
{
File.Delete(path);
}
public IEnumerable<string> SplitLines(string value)
{
return value.Split(new[] { NewLine }, StringSplitOptions.None);
}
public Stream CreateFileStream(string filePath, FileMode mode)
{
return new FileStream(filePath, mode);
}
public string GetWorkingDirectory(string path)
{
var realPath = GetFullPath(path);
var attributes = File.GetAttributes(realPath);
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
return realPath;
else
return Path.GetDirectoryName(realPath);
}
public string GetFullPath(string path)
{
return Path.GetFullPath(path);
}
}
}