DeleteDirectory Procedure

Deletes a directory, and optionally any subdirectories or files inside it.
By default, the directory must be empty, or the error code ERR_DIRECTORY_NOT_EMPTY is thrown. But if the recursive parameter is provided as true, then any contents of the directory will be deleted.
In rare circumstances, it is possible for ERR_DIRECTORY_NOT_EMPTY to be thrown even when recursive is set to true. This can happen if other programs on the computer create files in the directory while TMBASIC is trying to delete it.

Overload #1: DeleteDirectory(path)

Declaration
sub DeleteDirectory(path as String)

Parameters

Possible error codes

Example

Code
' create a new subdirectory in the current directory
CreateDirectory "testdir"
' create a file in that directory
dim filePath = PathCombine(["testdir", "test.txt"])
WriteFileText filePath, "hello world!"
' this throws an error because the directory is not empty
DeleteDirectory "testdir"

Overload #2: DeleteDirectory(path, recursive)

Declaration
sub DeleteDirectory(
path as String, recursive as Boolean
)

Parameters

Possible error codes

Example

Code
' create a new subdirectory in the current directory
CreateDirectory "testdir"
' create a file in that directory
dim filePath = PathCombine(["testdir", "test.txt"])
WriteFileText filePath, "hello world!"
' delete the directory and the file inside it
DeleteDirectory "testdir", true