How to create a folder using VBScript – FileSystemObject

FileSystemObject can be used to create a folder using VBScript. FileSystemObject also known as fso is one of the most efficient tools provided by VBScript. We can seamlessly perform so many operations on folders and files using fso in the simplest way.  

This page has VBScript functions using fso in VBScript for all the commonly used operations related to handling folders. eg. create a folder, copy a folder, delete a folder, etc.

FSO can also handle file operations. To know more about how to work with files using VBScript and FSO, check our post –

Example code – How to create a folder using VBScript (fso) in VBScript
Function createFolder()
 Set fso=createobject("Scripting.FileSystemObject")
 'Folder to be created 
 Foldername="D:\Folder_create"
 'If the folder doenot exist then create the folder
 If fso.FolderExists(Foldername) = false Then
  fso.CreateFolder (Foldername)
 End If
 Set fso=nothing
End Function
How to copy a folder using fso in VBScript
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created 
SourcePath="D:\Folder_create"
DestinationPath="D:\Destination"
'If the folder doesnot exist then create the folder
If fso.FolderExists(DestinationPath) = false Then
 fso.CreateFolder (DestinationPath)
End If
fso.CopyFolder  SourcePath,DestinationPath,True
Set fso=nothing
How to move a folder using fso in VBScript
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created 
SourcePath="D:\Folder_move"
DestinationPath="D:\Destination"
'If the folder doesnot exist then create the folder
If fso.FolderExists(DestinationPath) = false Then
 fso.CreateFolder (DestinationPath)
End If
fso.MoveFolder  SourcePath,DestinationPath
Set fso=nothing
How to delete a folder using fso in VBScript
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be  deleted.  
FolderDel="D:\final1"  'Delete the folder
fso.DeleteFolder(FolderDel)
Set fso=nothing
How to check if a folder exists using fso in VBScript
Set fso=createobject("Scripting.FileSystemObject")
'The Folder to check the existence
folderpath= "D:\qtp"
If fso.FolderExists(folderpath)  then
 msgbox  "Folder Exists"
Else
 Msgbox "Folder doesnot Exist"
End If
Set fso=nothing
How to check if a drive exists using fso in VBScript
Set fso=createobject("Scripting.FileSystemObject")
'The drive to check the existence
drivepath="D:"
If fso.DriveExists(drivepath) then
    msgbox  "Drive Exists"  
Else    
   Msgbox "Drive doesnot Exist"
End If
Set fso=nothing
How to get details of Drive using fso in VBScript
Set fso=createobject("Scripting.FileSystemObject")
'Drive for  getting details  
Sourcefile="C:"  
Set get_drv=fso.GetDrive(Sourcefile)
'Some of the following details can be retrieved from a drive
msgbox  get_drv.AvailableSpace
Msgbox  get_drv.DriveLetter
msgbox  get_drv.DriveType
msgbox  get_drv.FileSystem
msgbox  get_drv.FreeSpace
msgbox  get_drv.Path
Msgbox  get_drv.RootFolder
Msgbox  get_drv.SerialNumber
Msgbox  get_drv.TotalSize
Set fso=nothing

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.