35 for (
int i = 0; i < parts.Length - 1; i++)
45 return current.
FileExists(parts[parts.Length - 1]);
52 if (parts.Length == 1 &&
string.IsNullOrEmpty(parts[0]))
59 foreach (
string t
in parts)
61 if (!current.DirectoryExists(t))
72 public IEnumerable<string>
GetFiles(
string path,
string extension,
bool recursive)
97 for (
int i = 0; i < parts.Length - 1; i++)
103 throw new IOException(
"Directory does not exist");
140 throw new FileNotFoundException(fullPath);
156 throw new FileNotFoundException(path);
174 throw new DirectoryNotFoundException(path);
180 public void Copy(
string src,
string dst,
bool overwrite =
true)
186 throw new IOException(
"Cannot copy a directory to a subfolder of itself.");
191 throw new IOException(
"Directory already exists.");
198 if (!overwrite &&
IsFile(src))
200 throw new IOException(
"File already exists.");
207 throw new IOException(
"Source path is not a file or directory");
211 public void Move(
string src,
string dst,
bool overwrite =
true)
213 Copy(src, dst, overwrite);
275 return directory.
Directories.Select(sub => sub.AbsolutePath);
307 return from file in directory.Files where extension ==
"" || Path.GetExtension(file.Name) == extension select file.AbsolutePath;
318 foreach (
string file
in GetFiles(directory, extension))
367 foreach (
string file
in GetFiles(src,
"*",
true))
Represents a Virtual File System Directory Entry.
BadVirtualDirectory GetDirectory(string name)
Returns an existing directory.
BadVirtualFile GetFile(string name)
Returns an existing File.
void DeleteDirectory(string name, bool recursive=true)
Deletes a subdirectory with the specified name.
bool FileExists(string name)
Returns true if the file with the specified name exist in this directory.
BadVirtualDirectory CreateDirectory(string name)
Returns the existing directory or Creates a new directory with the specified name.
IEnumerable< BadVirtualDirectory > Directories
Subdirectories.
void DeleteFile(string name)
Deletes a file from the current directory.
bool DirectoryExists(string name)
Returns true if the directory with the specified name exist in this directory.
BadVirtualFile GetOrCreateFile(string name)
Returns an existing file or creates a new file with the specified name.
Stream OpenWrite(BadWriteMode mode)
Returns a writable stream for the file.
Stream OpenRead()
Returns a readable stream for the file.
Virtual File System Implementation for the BadScript Engine.
Stream OpenWrite(string path, BadWriteMode mode)
Opens a file for writing.
void Move(string src, string dst, bool overwrite=true)
Moves a file or directory to a new location.
static IEnumerable< string > GetFiles(BadVirtualDirectory directory, string extension)
Returns the files in the specified path that match the specified extension.
bool IsFile(string path)
Returns true if the given path is a file.
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.
string GetCurrentDirectory()
Returns the Current Directory.
void CopyFileToFile(string src, string dst)
Copies a file to a file.
BadVirtualDirectory GetDirectory(string path)
Returns the directory at the specified path.
BadVirtualRoot GetRoot()
Returns the root directory of the filesystem.
IEnumerable< string > GetDirectoriesRecursive(BadVirtualDirectory directory)
Returns the directories in the specified path recursively.
string GetStartupDirectory()
The Startup Directory of the Application.
bool IsSubfolderOf(string root, string sub)
Returns true if sub is a subfolder of root.
void DeleteDirectory(string path, bool recursive)
Deletes a directory.
BadVirtualDirectory GetParentDirectory(string path)
Returns the Parent directory of the specified path.
Stream OpenRead(string path)
Opens a file for reading.
void SetCurrentDirectory(string path)
Sets the current Directory.
bool Exists(string path)
Returns true if the given path is a file or directory.
void CopyDirectoryToDirectory(string src, string dst)
Copies a directory to a directory.
static IEnumerable< string > GetDirectories(BadVirtualDirectory directory)
Returns the directories in the specified path.
IEnumerable< string > GetFilesRecursive(BadVirtualDirectory directory, string extension)
Returns the files in the specified path that match the specified extension recursively.
string GetFullPath(string path)
Returns the full path of the given path.
string m_CurrentDirectory
The Current Directory.
void DeleteFile(string path)
Deletes a file.
readonly BadVirtualRoot m_Root
The Root Directory.
void Copy(string src, string dst, bool overwrite=true)
Copies a file or directory to a new location.
bool IsDirectory(string path)
Returns true if the given path is a directory.
void CreateDirectory(string path, bool recursive=false)
Creates a new directory.
Implements Operations to read and manipulate File System Paths.
static string[] SplitPath(string path)
static string JoinPath(IEnumerable< string > parts)
static bool IsRootPath(string path)
static string ResolvePath(string path, string currentDir)
Implements a Virtual File System Root Directory.
Defines the interface for a file system.
Contains the Implementation of the BadScript Virtual File System.
BadWriteMode
The Write Modes of the File System Abstraction.
Contains Utility Functions and Classes.