forked from pauldotknopf/dotnet-buildary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.cs
52 lines (45 loc) · 1.6 KB
/
File.cs
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
using System.Collections.Generic;
using System.Linq;
namespace Build.Buildary
{
public static class File
{
public static bool FileExists(string path)
{
return System.IO.File.Exists(path);
}
public static void DeleteFile(string file)
{
System.IO.File.Delete(file);
}
public static void WriteFile(string file, string content)
{
System.IO.File.WriteAllText(file, content);
}
public static void ReplaceInFile(string file, string oldValue, string newValue)
{
string text = System.IO.File.ReadAllText(file);
text = text.Replace(oldValue, newValue);
System.IO.File.WriteAllText(file, text);
}
public static List<string> GetFiles(string directory, string pattern = null, bool recursive = false)
{
var searchOptions = recursive ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly;
return !string.IsNullOrEmpty(pattern)
? System.IO.Directory.GetFiles(directory, pattern, searchOptions).ToList()
: System.IO.Directory.GetFiles(directory, "*", searchOptions).ToList();
}
public static void CopyFile(string source, string destination)
{
if (FileExists(destination))
{
DeleteFile(destination);
}
System.IO.File.Copy(source, destination);
}
public static string ReadFile(string file)
{
return System.IO.File.ReadAllText(file);
}
}
}