'####################################################################
'Working with FileSystemObject in VB Script for QTP/UFT
'Author: Vikas
'####################################################################
'1.Working with Folder/Directory
'1.1 How to Create a New Folder in QTP/UFT using VB Script(Visual Basic Script) ?
Dim objFso,objFolder
Set objFso=CreateObject("Scripting.FileSystemObject")
'this CreateFolder method shall create a new folder if it does not exists 'in "D:\Music" Drive
' else it will throw an error
Set objFolder=objFso.CreateFolder("D:\Music\New Folder1")
Output :
'1.2 How to display folder path ?
' Path method displays the path of the folder
strFolderPath=objFolder.Path
Msgbox strFolderPath
Output :
'1.3 How to copy folder/directory in QTP/UFT ?
' copy method of Folder object copies "New Folder1" created in 1.1, shall be copied to
path "D:\Movies\"
objFolder.Copy("D:\Movies\")
'1.4 How to get Creation Date and time of any Folder in QTP/UFT ?
'DateCreated properties of Folder object displays the creation date of "New Folder1"
strDate=objFolder.DateCreated
Msgbox strDate
Output:
'1.5 How to get/access folder Name in QTP/UFT ?
' Name property of Folder object displays Name of the directory it was created in 1.1
strFolderName =objFolder.Name
Msgbox strFolderName
Output:
'1.6 How to get Parent folder name in QTP/ UFT ?
'ParentFolder property of Folder object displays parent folder name
strParentFolerName=objFolder.ParentFolder
Msgbox strParentFolerName
Ouput:
'1.7 How to get/access Drive name that contains the folder ?
'Drive property of Folder objects displays the Drive name
strFolderDriveName=objFolder.Drive
Msgbox strFolderDriveName
Output:
'1.8 How to get/access size folder in QTP/UFT ?
'Size property of Folder object displays Sum of files and sub folders inside "New Folder1"
'(created in 1.1)
intFolderSize=objFolder.size
Msgbox intFolderSize
Output:Show as 0 because there nothing inside 'New Folder1'
'1.9 How to Move folder "New Folder1" to other place in UFT/QTP ?
'Move method of Folder object moves "New Folder1" ,which is located in drive
"D:\ Music\" to ' "D:\Games\"
objFolder.Move ("D:\Games\")
'1.9.1 How to Delete Folder/Directory in UFT/QTP using VB Script ?
'Delete method of Folder object deletes the directory "New Folder1" created in D:\ Music\" (1.1)
objFolder.Delete
'1.9.2 How to Create and Folder and a new text file using VB Script ?
'Please note a new Folder "New Folder1" has already been created in 1.1
'CreateTextFile method of Folder object create a new text file "Test.txt" and shall be overwritten
' if already exists
objFolder.CreateTextFile "D:\Music\New Folder1\Test.txt",true
Output:An empty text file created
'Working with FileSystemObject in VB Script for QTP/UFT
'Author: Vikas
'####################################################################
'1.Working with Folder/Directory
'1.1 How to Create a New Folder in QTP/UFT using VB Script(Visual Basic Script) ?
Dim objFso,objFolder
Set objFso=CreateObject("Scripting.FileSystemObject")
'this CreateFolder method shall create a new folder if it does not exists 'in "D:\Music" Drive
' else it will throw an error
Set objFolder=objFso.CreateFolder("D:\Music\New Folder1")
Output :
'1.2 How to display folder path ?
' Path method displays the path of the folder
strFolderPath=objFolder.Path
Msgbox strFolderPath
Output :
'1.3 How to copy folder/directory in QTP/UFT ?
' copy method of Folder object copies "New Folder1" created in 1.1, shall be copied to
path "D:\Movies\"
objFolder.Copy("D:\Movies\")
'1.4 How to get Creation Date and time of any Folder in QTP/UFT ?
'DateCreated properties of Folder object displays the creation date of "New Folder1"
strDate=objFolder.DateCreated
Msgbox strDate
Output:
'1.5 How to get/access folder Name in QTP/UFT ?
' Name property of Folder object displays Name of the directory it was created in 1.1
strFolderName =objFolder.Name
Msgbox strFolderName
Output:
'1.6 How to get Parent folder name in QTP/ UFT ?
'ParentFolder property of Folder object displays parent folder name
strParentFolerName=objFolder.ParentFolder
Msgbox strParentFolerName
Ouput:
'1.7 How to get/access Drive name that contains the folder ?
'Drive property of Folder objects displays the Drive name
strFolderDriveName=objFolder.Drive
Msgbox strFolderDriveName
Output:
'1.8 How to get/access size folder in QTP/UFT ?
'Size property of Folder object displays Sum of files and sub folders inside "New Folder1"
'(created in 1.1)
intFolderSize=objFolder.size
Msgbox intFolderSize
Output:Show as 0 because there nothing inside 'New Folder1'
'1.9 How to Move folder "New Folder1" to other place in UFT/QTP ?
'Move method of Folder object moves "New Folder1" ,which is located in drive
"D:\ Music\" to ' "D:\Games\"
objFolder.Move ("D:\Games\")
'1.9.1 How to Delete Folder/Directory in UFT/QTP using VB Script ?
'Delete method of Folder object deletes the directory "New Folder1" created in D:\ Music\" (1.1)
objFolder.Delete
'1.9.2 How to Create and Folder and a new text file using VB Script ?
'Please note a new Folder "New Folder1" has already been created in 1.1
'CreateTextFile method of Folder object create a new text file "Test.txt" and shall be overwritten
' if already exists
objFolder.CreateTextFile "D:\Music\New Folder1\Test.txt",true
Output:An empty text file created
0 comments: