1 Open your favorite text editor. In our case we are going to use Notepad++
2 Copy the VBScript code from below.
3 Paste the code in the newly created file.
4 Save the file with a ".vbs" extension.
5 Run the script file by double-clicking on it or via the CMD console.
6 That's it!
Advertisement
Code
' This script creates a folder.
Sub createFolder()
' Set variables
Dim fso
Dim folderName
Dim folderPath
Dim folderToBeCreated
Dim msg
' Set folder path
folderPath = "F:\VBAmacros\VBScript\"
' Set folder name
folderName = "My Folder"
' Ser folder to be created
folderToBeCreated = folderPath & folderName
' Create a file system object
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
' Check if the folder already exists
If fso.FolderExists(folderToBeCreated) Then
' Set a message
msg = "Warning! " & folderName & " already exists!"
' Output a message
MsgBox msg
Else
' Create folder
fso.CreateFolder(folderToBeCreated)
' Set a message
msg = "Success! " & folderName & " was successfully created!"
' Output a message
MsgBox msg
End If
' Release the file system object
Set fso = Nothing
End Sub
' Run the procedure
Call createFolder()