-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOS.cs
61 lines (61 loc) · 2.01 KB
/
OS.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
53
54
55
56
57
58
59
60
61
using System.Runtime.InteropServices;
public class OS {
[DllImport("msvcrt.dll")]
public static extern int system(string Command);
public static void mkdir(string dir) {
try {
if (!System.IO.Directory.Exists(dir)) {
System.IO.Directory.CreateDirectory(dir);
}
}
catch (IOException) {
Console.WriteLine("Error: an exception occurred while trying to create the directory");
}
}
public static void chdir(string dir) {
try {
System.IO.Directory.SetCurrentDirectory(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), dir));
}
catch (System.IO.DirectoryNotFoundException) {
Console.WriteLine($"Error: no such directory ({dir})");
}
}
public static string getcwd() {
return System.IO.Directory.GetCurrentDirectory();
}
public static void rmdir (string dir) {
if (!System.IO.Directory.Exists(dir)) {
Console.WriteLine($"Error: Directory ({dir}) does not exist");
}
try {
System.IO.Directory.Delete(dir);
}
catch (System.IO.DirectoryNotFoundException) {
Console.WriteLine($"Error: no such directory ({dir})");
}
}
public static void remove (string file) {
if (System.IO.File.Exists(file)) {
Console.WriteLine($"Error: File ({file}) does not exist");
}
else {
System.IO.File.Delete(file);
}
}
public static void create (string file) {
if(System.IO.File.Exists(file)) {
Console.WriteLine($"Error: File ({file}) already exists");
}
else {
System.IO.File.Create(file);
}
}
public static void copy (string source, string destination) {
try {
System.IO.File.Copy(source, destination);
}
catch (System.IO.IOException) {
Console.WriteLine($"Error: Cant copy {source} to {destination}");
}
}
}