Create a Folder/Directory in VB Script

In VB Script we can create a folder/directory using the 'CreateFolder' function of the File System Object. Following is the syntax of CreateFolder function

CreateFolder("Folder Name") 

The argument "folder name" can be just folder name or folder name with complete path. If a folder with same name exist the vbscript will generate an error. So its better to always check whether the folder exists before creating. Following is an example which demonstrate the use of this function

Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")

If fs.FolderExists("C:\Test Folder") Then
	WScript.Echo("Folder already exists. Cannot create folder")
Else
	fs.CreateFolder("C:\Test Folder")
End If

 

Powered by Bullraider.com