0% found this document useful (0 votes)
39 views

'Size A Folder

The document contains code snippets for performing various operations with folders and files using the FileSystemObject in VBScript, such as getting a folder size, copying, moving, deleting folders, getting file and subfolder counts, adding new folders, retrieving filenames and subfolders, and working with web lists in QuickTest Professional scripts.

Uploaded by

Soffia Soni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

'Size A Folder

The document contains code snippets for performing various operations with folders and files using the FileSystemObject in VBScript, such as getting a folder size, copying, moving, deleting folders, getting file and subfolder counts, adding new folders, retrieving filenames and subfolders, and working with web lists in QuickTest Professional scripts.

Uploaded by

Soffia Soni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

'Size a Folder Dim SourceFolder, oFSO SourceFolder = "C:\IM" Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.

GetFolder(SourceFolder) Msgbox "Size of the Folder "&oFSO.Size&" bytes" 'Display the size of the folder

'Copy a Folder Dim SourceFolder, oFSO SourceFolder = "C:\IM" Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.CopyFolder SourceFolder, "D:\"

'Move a Folder Dim SourceFolder, DestinationFolder, oFSO SourceFolder = "C:\IM" DestinationFolder = "D:\" Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.MoveFolder SourceFolder, DestinationFolder

[email protected]

'Delete a Folder Dim SourceFolder, oFSO SourceFolder = "D:\IM" Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.DeleteFolder SourceFolder

'Get the File Count in a folder Set FSO = CreateObject("Scripting.FileSystemObject") FolderPath = "C:\Documents and Settings\" Set TestFolder = FSO.GetFolder(FolderPath) Set Files = TestFolder.Files MsgBox("Number of Files in:"&vbCrLf&FolderPath&vbcrlf&Files.Count)

'Get the SubFolder Count in a Folder Set FSO = CreateObject("Scripting.FileSystemObject") Set TestFolder = FSO.GetFolder("C:\Documents and Settings") Set SubFolders = TestFolder.SubFolders 'Returns the collection of subfolders Msgbox(SubFolders.Count)

[email protected]

'Add a New Folder Sub AddNewFolder(FolderPath, FolderName) Dim FSO, f, fc,nf Set FSO = CreateObject("Scripting.FileSystemObject") Set f = FSO.GetFolder(FolderPath) Set fc = f.SubFolders If FolderName <> "" Then Set nf = fc.Add(FolderName) Else Set nf = fc.Add("New Folder") End If End Sub AddNewFolder "C:\",""

'Filenames in a Folder Folderpath = "C:\MyFolder" Dim FSO, oFolder Set FSO = CreateObject("Scripting.FileSystemObject") Set oFolder = FSO.GetFolder(FolderPath) Files = oFolder.Files 'Gets the collection of files in a folder For each file in Files Msgbox File.Name Next 'SubFoldernames in a Folder Folderpath = "C:\MyFolder" Dim FSO, oFolder Set FSO = CreateObject("Scripting.FileSystemObject") Set oFolder = FSO.GetFolder(FolderPath) Folders = oFolder.SubFolders 'Gets the collection of subfolders in a folder For each folder in Folders Msgbox folder.Name Next

[email protected]

Working with WebList To check whether weblist is exist on page or not. Var=Browser(title:=browser).Page(title:=page).WebList(html id:=name).Exist(10) Msgbox var If var returns true then weblist exist on page. Click on Weblist Browser(title:=browser).Page(title:=page).WebList(html id:=name).Click Get particular item from weblist Var=Browser(title:=browser).Page(title:=page).WebList(html id:=name).GetItem(2) Msgbox var Var return second element from the weblist To get count of Weblist item Var= Browser(title:=browser).Page(title:=page).WebList(html id:=name).GetROProperty(items count) Msgbox var To select particular item from list Browser(title:=browser).Page(title:=page).WebList(html id:=name).Select(2) It will select second item from the list To count how many weblist exist on the page Set oDesc = Description.Create() oDesc("micclass").Value = "WebList" Set Lists = Browser(title:=browser).Page(title:=page).ChildObjects(oDesc) NumberOfLists = Lists.Count()
[email protected]

Msgbox NumberOfLists To get last element from weblist Itemcnt= Browser(title:=browser).Page(title:=page).WebList(html id:=name).GetROProperty(items count) Itemvalue= Browser(title:=browser).Page(title:=page).WebList(html id:=name).GetItem(Itemcnt) Browser(title:=browser).Page(title:=page).WebList(html id:=name).Select Itemvalue

[email protected]

How to check a value exists in a weblist using QTP noItems=browser("name:=Web*.*").page("title:=Web*.*").weblist("name:=depart").Ge tROProperty("items count") flag=false For i=1 to noItems If lcase(browser("name:=Web*.*").page("title:=Web*.*").weblist("name:=depart").GetIte m(i))="uday" then flag=true end if Next If flag=true Then msgbox "Exists" else msgbox "Not Exists" End If

[email protected]

Retrieving data from web table '********************************************************************** rCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").RowCount For r=1 to rCount cCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ColumnCount(r) For c=1 to cCount cData=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").GetCellData(r,c) msgbox cData Next Next

[email protected]

Accessing child objects from web table

Set oWebEdit=Description.Create oWebEdit("micclass").value="WebEdit" set objList=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ChildObjects(oWebEdit) For objIndex=0 to objlist.count-1 msgbox objlist(objIndex).getroproperty("html id") Next

[email protected]

Accessing child objects from web table cell

'********************************************************************** rCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").RowCount For r=1 to rCount cCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ColumnCount(r) For c=1 to cCount oCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ChildItemCount(r,c,"WebEdit") For obj=0 to oCount-1 set cObject=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ChildItem(r,c,"WebEdit",obj) msgbox cObject.getROproperty("html id") Next Next Next '**********************************************************************

[email protected]

Difference between childobject, childitem and Getcelldata methods ChildObjects method is to access total child objects from web table object using description object. Syntax:- object.ChildObjects ([Description]) ChildItem method is to access child objects from a web table cell in web table object without using description object. Syntax:-object.ChildItem (Row, Column, MicClass, Index) Getcelldata method is to retrieve data from a web table cell in web table object. Syntax:-object.GetCellData (Row, Column)

[email protected]

You might also like