Search This Blog

Wednesday, June 1, 2011

FileSystemObject : Working with Folders

The FSO object model gives your server-side applications the ability to create, alter, move, and delete folders, or to detect if particular folders exist, and if so, where. You can also find out information about folders, such as their names, the date they were created or last modified, and so forth.
The FSO object model also makes it easy to process files. When processing files, the primary goal is to store data in a space- and resource-efficient, easy-to-access format. You need to be able to create files, insert and change the data, and output (read) the data.

FileSystemObject is main object. Contains methods and properties that allow you to create, delete, gain information about, and generally manipulate drives, folders, and files. Many of the methods associated with this object duplicate those in other FSO objects; they are provided for convenience.

Here I am presenting some basic scripts to Create Folder, Copy Folder,Delete Folder, Move Folder , See if Folder Exist or not.
working with this rich set of properties of FSO you need to firset cretae your FSO objec than use FileSystemObject methods provided.

Script to Create Folder :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")  
Set ofolder= fso.createfolder ("C:\QTP_FSO")                                

Script to Delete Folder :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.DeleteFolder (""C:\QTP_FSO")

Script To Copy Folder from One location to other:

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.CopyFolder "C:\QTP_FSO" , "D:\QTP\Functions\" ,True

Script To Move Folder from one location to other :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.MoveFolder "C:\QTP_FSO" , "D:\QTP\Functions\"

Script to Check if folder already exist :

Dim fso , ofolder
Set fso = createobject ("scripting.filesystemobject")
If fso.FolderExists("C:\QTP_FSO") Then
MsgBox "Folder Already Exist"
else
msgbox "Folder does not exist"
Set ofolder= fso.createfolder ("C:\QTP_FSO")
End If

No comments:

Post a Comment