Creating and Deleting Folders the MkDir and RmDir Statements

You can create a new folder using the following syntax of the MkDir statement:

MkDir Path

Path specifies the new folder that you want to create. If you don't include the name of the drive, Visual Basic will create the new folder on the current drive. Let's run through some examples:

1. Enter the instruction in the Immediate window to create a folder called "Mail" on drive C:

MkDir "C:\Mail"

2. Change the default folder to "C:\Mail": ChDir "C:\Mail"

3. Find out the name of the active folder: ?CurDir

To delete a folder you no longer need, use the RmDir function. This function has the following syntax:

RmDir Path

Path specifies the folder you want to delete. Path may include the drive name. If you omit the name of the drive, Visual Basic will delete the folder on the current drive if a folder with the same name exists. Otherwise, Visual Basic will display the error message "Path not found."

4. Delete the C:\Mail folder that was created earlier: RmDir "C:\Mail"

Tip 8-3: RmDir Removes Empty Folders

You cannot delete a folder if it still contains files. You should first delete the files with the Kill statement (discussed later in this chapter).

0 0

Post a comment