RmDirMkDir

=RmDir and MkDir= toc

Note: the terms "folder" and "directory" can be used interchangably.

MkDir
Run BASIC allows you to create a directory with **MkDir**. The syntax is as follows:

MKDIR(p$) //- Create directory path p$. Return 1 or 0 for success or failure respectively.//

If no path information is given, the root path of RBP is used. The following line attempts to create a directory called "test" in the root directory of RBP.

code a = mkdir("test") code

Here is code that also creates the "test" folder in the root directory. In this line, the DefaultDir$ variable holds the root directory information. The code functions in exactly the same way as the code above.

code a = mkdir(DefaultDir$ +"\test") code

MkDir Failure
If a directory with the same name already exists, **MkDir** fails. The following code creates a directory, then attempts to create it again. The first attempt is successful. The second attempt fails, because the directory already exists.

code a = mkdir(DefaultDir$ +"\something") if a then print "Directory created." else print "Unable to create directory." end if

a = mkdir(DefaultDir$ +"\something") if a then print "Directory created." else print "Unable to create directory." end if code

If path information is given, it must be an existing path. The following code creates a directory in the RBP DOCS directory.

code a = mkdir(DefaultDir$ +"\docs\test") code

This code fails if there is not an existing directory "c:\whatever"

code a = mkdir("c:\whatever\test") code

RmDir
Run BASIC allows you to remove a directory with **RmDir**. The syntax is as follows:

RMDIR(p$) //- Delete directory path p$. Return 1 or 0 for success or failure respectively.//

The following line attempts to remove a directory called "test".

code a = rmdir("test") code

RmDir Failure
If you attempt to remove a directory which does not exist, **RmDir** fails.

Demo
The following program attempts to create a directory called "test" in the root directory. The result of the function is evaluated and the user is given a notice of the success. The program then attempts to remove the created directory, again giving the user a notice of the results.

code format="vbnet" a = mkdir("test") if a then print "Directory created." else print "Unable to create directory." end if

a = rmdir("test") if a then print "Directory removed." else print "Unable to remove directory." end if code