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
- path as String — Directory path.
Possible error codes
- ERR_ACCESS_DENIED
- ERR_DIRECTORY_NOT_EMPTY
- ERR_DISK_FULL
- ERR_IO_FAILURE
- ERR_PATH_TOO_LONG
Example
Code
CreateDirectory "testdir"
dim filePath = PathCombine(["testdir", "test.txt"])
WriteFileText filePath, "hello world!"
DeleteDirectory "testdir"
Overload #2: DeleteDirectory(path, recursive)
Declaration
sub DeleteDirectory(
path as String, recursive as Boolean
)
Parameters
- path as String — Directory path.
- recursive as Boolean — If true, any subdirectories and files inside the directory will be deleted.
If false, then the directory must already be empty, otherwise the error code ERR_DIRECTORY_NOT_EMPTY is thrown.
Possible error codes
- ERR_ACCESS_DENIED
- ERR_DIRECTORY_NOT_EMPTY
- ERR_DISK_FULL
- ERR_IO_FAILURE
- ERR_PATH_TOO_LONG
Example
Code
CreateDirectory "testdir"
dim filePath = PathCombine(["testdir", "test.txt"])
WriteFileText filePath, "hello world!"
DeleteDirectory "testdir", true