10 return AppDomain.CurrentDomain.BaseDirectory;
15 return Directory.Exists(path) || File.Exists(path);
20 return File.Exists(path);
25 return Directory.Exists(path);
28 public IEnumerable<string>
GetFiles(
string path,
string extension,
bool recursive)
30 return Directory.GetFiles(
33 recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly
39 return Directory.GetDirectories(
42 recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly
48 List<string> directories =
new List<string>();
52 while (current !=
null)
54 directories.Add(current);
55 current = Path.GetDirectoryName(current)!;
58 for (
int i = directories.Count - 1; i >= 0; i--)
60 if (!Directory.Exists(directories[i]))
62 Directory.CreateDirectory(directories[i]);
69 Directory.Delete(path, recursive);
79 return Path.GetFullPath(path);
84 return File.OpenRead(path);
89 FileMode fileMode = mode
switch
91 BadWriteMode.CreateNew => FileMode.Create,
92 BadWriteMode.Append => FileMode.Append,
93 _ =>
throw new ArgumentOutOfRangeException(nameof(mode), mode,
null),
96 return File.Open(path, fileMode);
101 return Directory.GetCurrentDirectory();
106 Directory.SetCurrentDirectory(path);
109 public void Copy(
string src,
string dst,
bool overwrite =
true)
111 if (File.Exists(src))
113 if (!overwrite && File.Exists(dst))
115 throw new IOException(
"File already exists");
118 File.Copy(src, dst, overwrite);
120 else if (Directory.Exists(src))
122 if (!overwrite && Directory.Exists(dst))
124 throw new IOException(
"Directory already exists");
127 foreach (
string directory
in Directory.GetDirectories(src,
"*", SearchOption.AllDirectories))
129 Directory.CreateDirectory(directory.Replace(src, dst));
132 foreach (
string file
in Directory.GetFiles(src,
"*", SearchOption.AllDirectories))
134 File.Copy(file, file.Replace(src, dst), overwrite);
139 public void Move(
string src,
string dst,
bool overwrite =
true)
141 if (File.Exists(src))
143 if (!overwrite && File.Exists(dst))
145 throw new IOException(
"File already exists");
150 else if (Directory.Exists(src))
152 if (!overwrite && Directory.Exists(dst))
154 throw new IOException(
"Directory already exists");
157 Directory.Move(src, dst);
Implements a wrapper for the actual OS file system.
bool IsFile(string path)
Returns true if the given path is a file.
Stream OpenRead(string path)
Opens a file for reading.
IEnumerable< string > GetDirectories(string path, bool recursive)
Returns all directories in the given directory.
IEnumerable< string > GetFiles(string path, string extension, bool recursive)
Returns all files in the given directory that match the specified extension.
void CreateDirectory(string path, bool recursive=false)
Creates a new directory.
bool IsDirectory(string path)
Returns true if the given path is a directory.
void DeleteFile(string path)
Deletes a file.
Stream OpenWrite(string path, BadWriteMode mode)
Opens a file for writing.
bool Exists(string path)
Returns true if the given path is a file or directory.
void Copy(string src, string dst, bool overwrite=true)
Copies a file or directory to a new location.
void SetCurrentDirectory(string path)
Sets the current Directory.
string GetStartupDirectory()
The Startup Directory of the Application.
string GetCurrentDirectory()
Returns the Current Directory.
void Move(string src, string dst, bool overwrite=true)
Moves a file or directory to a new location.
string GetFullPath(string path)
Returns the full path of the given path.
void DeleteDirectory(string path, bool recursive)
Deletes a directory.
Defines the interface for a file system.
Contains IO Implementation for the BadScript2 Runtime.
BadWriteMode
The Write Modes of the File System Abstraction.