Archive for January, 2010

Get File count and found matching file name VB script

Posted by rajivkumarnandvani on January 7, 2010

Dim fs ‘ variable declared outside a procedure (this is a global variable)
‘ this is hold a reference to the file system object
”create an instance
On Error Resume Next
Set fs = CreateObject(“scripting.filesystemobject”)
Set MyFile = fs.CreateTextFile(“c:\Filepath.txt”,True,True)

‘ count files in windows directory
folderpathvalue = inputbox (“Plese Enter Folder path” ,”Folder”,”C:\WINDOWS\”)
FileNamevalue = inputbox (“Plese Enter File name/extension of file” ,”FileName”,”.txt”)
Filecountvalue = CountFiles (folderpathvalue , FileNamevalue )
Set WshShell = CreateObject(“WScript.Shell”)
Set MyFile = nothing
Set fs = nothing
rem it will return the total file count value not the matching file count value
msgbox “Total File count is ” & Filecountvalue
rem it will show the how many file found with matching criteria“c:\Filepath.txt”)
Set WshShell =nothing

‘ takes a string argument containing the name of the directory

‘ returns an integer contiang the nubmer of files in that direcrectory

‘ and all sub directories

Function CountFiles (ByVal StrFolder ,byval FileNamevalue)
Dim ParentFld
Dim SubFld
Dim IntCount
‘ note the use of the fs global variable
Set ParentFld = fs.GetFolder (StrFolder)
‘ count the number of files in the current directory
IntCount = ParentFld.Files.Count
For Each oFile In ParentFld.files
On Error Resume Next
If InStr(1, lcase(oFile.path),FileNamevalue) > 0 then
MyFile.writeline oFile.path
end If
For Each SubFld In ParentFld.SubFolders
‘ count all files in each subfolder – recursion point
IntCount = IntCount + CountFiles(SubFld.Path ,FileNamevalue)
‘ return counted files
CountFiles = IntCount
End Function

Posted in QTP | Tagged: , , , | Leave a Comment »

Check page broken link using VB script

Posted by rajivkumarnandvani on January 5, 2010

I created a script that will check broken link in a page means valid url is that or not by using Microsoft.XMLHTTP object

rem create link object description
Set alllinkob = Description.Create()
alllinkob(“micclass”).value =”Link”
alllinkob(“html tag”).value =”A”

rem get alllink objects
set objAlllinkObj = Browser(“Google”).Page(“Google”).ChildObjects(alllinkob)
rem run a loop as per link on the page
For a =0 to objAlllinkObj.count-1
rem get link url
url = objAlllinkObj(a).getroproperty(“url”)
rem call function
call geturlstatus(url )


Set objAlllinkObj = nothing
rem Clear browser cache
Public Function ClearBrowserCache()
On Error Resume Next

rem TEMPORARY_INTERNET_FILES file path in system
Const TEMPORARY_INTERNET_FILES = 32’&H20& ‘Decimal 32 is equivalent to hex value &H20&

rem create file system object
Set objCacheFSO = CreateObject(“Scripting.FileSystemObject”)

rem create shell application  object
Set objShell = CreateObject(“Shell.Application”)

rem create temporary folder path object
Set objFolder = objShell.Namespace(TEMPORARY_INTERNET_FILES)

Rem delete all file under temporary folder
objCacheFSO.DeleteFile(objFolder.Self.Path & “\*.*”)

Rem get cache folder path..

sPath = objCacheFSO.GetFolder(objFolder.Self.path) & “\Content.IE5\”

Rem create cache folder object..
Set objFolders = objCacheFSO.GetFolder(sPath)
For Each objFName In objFolders.SubFolders
‘WScript.Echo sPath & objFName.Name
objCacheFSO.DeleteFolder sPath & objFName.Name, True
ClearBrowserCache= True
Set objFolder=Nothing
Set objShell=Nothing
Set objCacheFSO=Nothing
End Function

Public Function geturlstatus(url )
On Error Resume Next
Call ClearBrowserCache()
Set webService = nothing
Set webService= CreateObject(“Microsoft.XMLHTTP”) “GET”, url, False
pagestatus = webService.status
If pagestatus < 200 or pagestatus >399 Then
print “In valid request “& pagestatus &” ” & url
geturlstatus = 0
geturlstatus = 1
print “valid request “& pagestatus &” ” & url
End If
Set webService = nothing
End Function

rem __________________________________________

url = “;

call geturlstatus(url )

Posted in QTP | Tagged: , | 45 Comments »

Using Date in VB script

Posted by rajivkumarnandvani on January 1, 2010

Hi All,
Some time we required date in different format like DD/MM/YY but when we use now or date function it will written the value as per ur system configuration date format like if today is 1st jan 2010 and we need the date in DD/MM/YY format means 01/01/2010 but it will written 1/1/2010 if date 31 jan 2010 then it will written 31/1/2010 while we need 31/01/10
so for this we can use in this way

dim dayvalue, monthvalue , yearvalue
dayvalue =right(“0″&day(now),2)
msgbox “dayvalue =” &dayvalue

monthvalue =right(“0″&month(now),2)
msgbox “monthvalue =” & monthvalue
msgbox “yearvalue =” & yearvalue

Posted in QTP | Tagged: | Leave a Comment »

%d bloggers like this: