Mkdir Statement is used to creates a new directory or folder.
Syntax:-
MkDir path
- Here Path is a string expression that identifies the directory or folder to be created.
- The path may include the drive.
- If no drive is specified, MkDir creates the new directory or folder on the current drive.
Example & Explanation
- Creating a folder or Directory
Here we are going to create a directory or folder in D drive using MkDir statement.
MkDir \"D:\\VBA\\Excel\"
This will create new directory named \”Excel \” in D drive placed in VBA folder.
- Creating Folder in another folder i.e. Sub-Folder
MkDir \"D:\\VBA\\Macros\"
This will create new Directory or folder named Macros inside VBA folder in D drive.
Note: – If the drive is not specified, the new directory or folder is created on the current drive.
MkDir \”Excel\”
The Above command will create a new folder named Excel in My document i.e. default Location for creating new folder if sub-folders are not specified.
RmDir statement
RmDir Statement is used to delete an existing directory or folder.
Syntax:-
RmDir path
- Here Path is a string expression that identifies the directory or folder to be removed.
- The path may include the drive.
For Example
- Removing a folder or Directory
Here we are going to remove use the RmDir statement to create a directory or folder in D drive.
RmDir \"D:\\VBA\\Excel\"
The above command will remove “Excel” folder in VBA folder in D drive
Note: –
An error occurs if you try to use RmDir on a directory or folder containing files. Use the Kill statement to delete all files before attempting to remove a directory or folder.
Kill statement
Kill Statement Deletes files from the give local disk.
Syntax
Kill pathname
The required pathname argument is a string expression that specifies one or more file names to be deleted. The pathname may include the directory or folder, and the drive.
In Microsoft Windows, Kill supports the use of multiple-character (*) and single-character (?) wildcards to specify multiple files.
Kill \"D:\\VBA\\excel\\data.txt\"
The above command will delete “data.txt” file present in excel folder in D drive.
Suppose we want to delete all text file present in same folder, then use below command
Kill \"D:\\VBA\\excel\\*.txt\"
If we want to delete All files starting with Letter N with .txt extension
Kill \"D:\\VBA\\excel\\N*.txt\"