BadScript 2
Loading...
Searching...
No Matches
BadDirectoryApi.cs
Go to the documentation of this file.
1using BadScript2.IO;
3
5
6[BadInteropApi("Directory", true)]
7internal partial class BadDirectoryApi
8{
13
14 public BadDirectoryApi(IFileSystem fileSystem) : this()
15 {
16 m_FileSystem = fileSystem;
17 }
18
19 [BadMethod(description: "Creates all directories and subdirectories in the specified path.")]
20 private void CreateDirectory([BadParameter(description: "The directory to create.")] string path)
21 {
23 }
24
25 [BadMethod(description: "Deletes the specified directory and, if indicated, any subdirectories in the directory.")]
26 [return: BadReturn("True if the directory exists; otherwise, false.")]
27 private bool Exists([BadParameter(description: "The Path to check")] string path)
28 {
29 return m_FileSystem.Exists(path) && m_FileSystem.IsDirectory(path);
30 }
31
32 [BadMethod(description: "Deletes the specified directory and, if indicated, any subdirectories in the directory.")]
33 private void Delete(
34 [BadParameter(description: "The Path to delete")]
35 string path,
36 [BadParameter(description: "If true, the directory will be deleted recursively")]
37 bool recursive)
38 {
39 m_FileSystem.DeleteDirectory(path, recursive);
40 }
41
42 [BadMethod(description: "Returns the Current Working Directory.")]
43 [return: BadReturn("The Current Working Directory")]
44 private string GetCurrentDirectory()
45 {
47 }
48
49 [BadMethod(description: "Sets the Current Working Directory.")]
50 private void SetCurrentDirectory([BadParameter(description: "The Path to set as the Current Working Directory.")] string path)
51 {
53 }
54
55 [BadMethod(description: "Returns the startup directory")]
56 [return: BadReturn("The startup directory")]
57 private string GetStartupDirectory()
58 {
60 }
61
62 [BadMethod(description: "Returns the directories in the specified directory.")]
63 [return: BadReturn("An array of directories in the specified directory.")]
65 [BadParameter(description: "The Path to get the directories from.")]
66 string path,
67 [BadParameter(description: "If true, the search will return all subdirectories recursively")]
68 bool recursive = false)
69 {
70 return new BadArray(m_FileSystem.GetDirectories(path, recursive).Select(x => (BadObject)x).ToList());
71 }
72
73 [BadMethod(description: "Returns the files in the specified directory.")]
74 [return: BadReturn("An array of files in the specified directory.")]
76 [BadParameter(description: "The Path to get the files from.")]
77 string path,
78 [BadParameter(description: "The search pattern.")]
79 string searchPattern = "",
80 [BadParameter(description: "If true, the search will return all subdirectories recursively")]
81 bool recursive = false)
82 {
83 return new BadArray(m_FileSystem.GetFiles(path, searchPattern, recursive).Select(x => (BadObject)x).ToList());
84 }
85
86 [BadMethod(description: "Moves a specified file to a new location, providing the option to specify a new file name.")]
87 private void Move(
88 [BadParameter(description: "The Path of the file to move")]
89 string source,
90 [BadParameter(description: "The Destination Path")]
91 string destination,
92 [BadParameter(description: "If true, allows an existing file to be overwritten; otherwise, false.")]
93 bool overwrite = false)
94 {
95 m_FileSystem.Move(source, destination, overwrite);
96 }
97
98 [BadMethod(description: "Copies a specified file to a new location, providing the option to specify a new file name.")]
99 private void Copy(
100 [BadParameter(description: "The Path of the file to copy")]
101 string source,
102 [BadParameter(description: "The Destination Path")]
103 string destination,
104 [BadParameter(description: "If true, allows an existing file to be overwritten; otherwise, false.")]
105 bool overwrite = false)
106 {
107 m_FileSystem.Copy(source, destination, overwrite);
108 }
109}
Public interface for the filesystem abstraction of the BadScript Engine.
static IFileSystem Instance
File System implementation.
bool Exists([BadParameter(description:"The Path to check")] string path)
void Delete([BadParameter(description:"The Path to delete")] string path, [BadParameter(description:"If true, the directory will be deleted recursively")] bool recursive)
void SetCurrentDirectory([BadParameter(description:"The Path to set as the Current Working Directory.")] string path)
BadArray GetFiles([BadParameter(description:"The Path to get the files from.")] string path, [BadParameter(description:"The search pattern.")] string searchPattern="", [BadParameter(description:"If true, the search will return all subdirectories recursively")] bool recursive=false)
BadDirectoryApi(IFileSystem fileSystem)
readonly IFileSystem m_FileSystem
The FileSystem Instance.
void Move([BadParameter(description:"The Path of the file to move")] string source, [BadParameter(description:"The Destination Path")] string destination, [BadParameter(description:"If true, allows an existing file to be overwritten; otherwise, false.")] bool overwrite=false)
void Copy([BadParameter(description:"The Path of the file to copy")] string source, [BadParameter(description:"The Destination Path")] string destination, [BadParameter(description:"If true, allows an existing file to be overwritten; otherwise, false.")] bool overwrite=false)
void CreateDirectory([BadParameter(description:"The directory to create.")] string path)
BadArray GetDirectories([BadParameter(description:"The Path to get the directories from.")] string path, [BadParameter(description:"If true, the search will return all subdirectories recursively")] bool recursive=false)
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Defines the interface for a file system.
Definition IFileSystem.cs:7
void SetCurrentDirectory(string path)
Sets the current Directory.
void DeleteDirectory(string path, bool recursive)
Deletes a directory.
bool IsDirectory(string path)
Returns true if the given path is a directory.
string GetCurrentDirectory()
Returns the Current Directory.
void CreateDirectory(string path, bool recursive=false)
Creates a new directory.
void Copy(string src, string dst, bool overwrite=true)
Copies a file or directory to a new location.
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 GetStartupDirectory()
The Startup Directory of the Application.
bool Exists(string path)
Returns true if the given path is a file or directory.
void Move(string src, string dst, bool overwrite=true)
Moves a file or directory to a new location.
Contains IO Implementation for the BadScript2 Runtime.
Contains IO Extensions and APIs for the BadScript2 Runtime.
Contains the Runtime Objects.
Definition BadArray.cs:10