Requirements on testing, QTP, QC, BPT and Automation frameworks information.
Search This Blog
Thursday, November 25, 2010
Functionality:- Getting User names and passwords from XML File to QTP.
Copy paste the below code in to a text file and save it as Login.xml
Note:The below code has 4 environments with different user id and passwords
--------------------------------------------------------------------------------
<Environment>
<Variable>
<ENV>UAT</ENV>
<ID>userid</ID>
<PSWD>Password</PSWD>
</Variable>
<Variable>
<ENV>PFIX</ENV>
<ID>userid</ID>
<PSWD>password</PSWD>
</Variable>
<Variable>
<ENV>PROD</ENV>
<ID></ID>
<PSWD></PSWD>
</Variable>
<Variable>
<ENV>SIT</ENV>
<ID>userid</ID>
<PSWD>password</PSWD>
</Variable>
</Environment>
-----------------------------------------------------------------------------------------
Step 2:- Use the below in QTP to get the data from xml file
-------------------------------------------------------------------------------------------
Public Function LoginUserInfo()
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\Login.xml") Then
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load("C:\Login.xml")
Set ENVnode = xmlDoc.getElementsByTagName("ENV")
Set IDnode = xmlDoc.getElementsByTagName("ID")
Set PSWDnode = xmlDoc.getElementsByTagName("PSWD")
ENVlength=ENVnode.length
IDlength=IDnode.length
PSWDlength=PSWDnode.length
Counter=1
for Counter=0 to ENVlength-1
ENVitem=ENVnode.item(Counter).Text
IDitem=IDnode.item(Counter).Text
PSWDitem= PSWDnode.item(Counter).Text
If (LEnv = ENVitem) Then
Environment.Value("ENV") = ENVitem
Environment.Value("UserID")=IDitem
Environment.Value("PSWD") = PSWDitem
ENV = Envitem
UserID = IDitem
PSWD = PSWDitem
Exit For
End If
Next
End If
End Function
--------------------------------------------------------------------------
Step 3:
From the above code you will get the data of login id , password and login environment in to the below variabels as
ENV= login environment
UserID= Login User ID
PSWD= Password
Wednesday, November 24, 2010
Functionality: Code for not locking the system by defeult while the script is running.
WSHShell.SendKeys "^%{F1}"
Functionality: Code for getting the future with the addition of on month to the current date
Functionality: Code for close to latest opened browser
Tuesday, November 23, 2010
Functionlity: Code for Disable or Enable Tabbed Browsing in IE8Function
Function EnableOrDisable_TabbedBrowsing(strEnableDisable)
Select Case strEnableDisable
Case "Disable"
hwnd2=Browser("name:=Sign On").GetROProperty("hwnd")
Dialog("hwnd:="&hwnd2).Type micAltDwn + "t" + micAltUp
Dialog("hwnd:="&hwnd2).Type micUp
Dialog("hwnd:="&hwnd2).Type
Wait(5)
Dialog("text:=Internet Options").Type micAltDwn + "t" + micAltUp
Dialog("text:=Tabbed Browsing Settings").WinCheckBox("text:=&Enable Tabbed Browsing \(requires restarting Internet Explorer\)").Set "OFF"
Dialog("text:=Tabbed Browsing Settings").WinButton("text:=OK").Click
Dialog("text:=Internet Options").WinButton("text:=OK").Click
Case "Enable"
hwnd2=Browser("name:=Sign On").GetROProperty("hwnd")
Dialog("hwnd:="&hwnd2).Type micAltDwn + "t" + micAltUp
Dialog("hwnd:="&hwnd2).Type micUp
Dialog("hwnd:="&hwnd2).Type mic Return
Wait(5)
Dialog("text:=Internet Options").Type micAltDwn + "t" + micAltUp
Dialog("text:=Tabbed Browsing Settings").WinCheckBox("text:=&Enable Tabbed Browsing \(requires restarting Internet Explorer\)").Set "ON"
Dialog("text:=Tabbed Browsing Settings").WinButton("text:=OK").Click Dialog("text:=Internet Options").WinButton("text:=OK").Click
End Select
End Function
Functionality : Close any Open Browser & Open PDF/Child window
Function Close_ANY_Browser (optsBrwName)
Set BrwDesc = Description.Create()
BrwDesc("micclass").Value = "Browser"
Set ObjIExpl = Description.Create
ObjIExpl("micclass").value = "Browser"
Set ObjIExplColl = Desktop.ChildObjects(ObjIExpl)
fGetBrowsersCount = ObjIExplColl.Count
rcBrwCount = fGetBrowsersCount-1
UnKnown_hwnd=Browser("CreationTime:="& rcBrwCount).GetROProperty("hwnd")
Get_title= Window("hwnd:="& UnKnown_hwnd).GetROProperty("title")
Get_name = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("name")
Get_openurl = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("openurl")
If Get_title = "" AND Get_name = "" Then
SetProperty = "openurl"
Else
SetProperty = "title"
End If
BrwDesc(SetProperty).Value = optsBrwName
If Get_title ="" AND Get_name = "" AND Get_openurl="" Then
Reporter.ReportEvent micFail,"DID NOT Get Property Values for an opened Child Window - Properties name/openurl/title were NOT assigned to the ChildWindow ","Choose another property to Perform Action - CLOSE on opened Child Window"
Else
Reporter.ReportEvent micPass,"Recognized the Child Window/Browser by using the property '" & SetProperty & "' ","Performs an Action CLOSE on opened Child Window"
SetProperty1=SetProperty & ":=" & optsBrwName
Browser(SetProperty1).Close
If NOT Browser(SetProperty1).Exist(0) Then
Close_ANY_Browser = True
End If
Set BrwDesc = Nothing
End If
End Function
Functionality: Code for maximize the browsers & Browsers count
Set BrwDesc = Description.Create()
BrwDesc("micclass").Value = "Browser"
rcBrwCount = fGetBrowsersCount()-1
UnKnown_hwnd=Browser("CreationTime:="& rcBrwCount).GetROProperty("hwnd")
Get_title= Window("hwnd:="& UnKnown_hwnd).GetROProperty("title")
Get_name = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("name")
Get_openurl = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("openurl")
If Get_title = "" AND Get_name = "" Then
SetProperty = "openurl"
Else
SetProperty = "title"
End If
BrwDesc(SetProperty).Value = optsBrwName
If Get_title ="" AND Get_name = "" AND Get_openurl="" Then
Reporter.ReportEvent micFail,"DID NOT Opens the Child Window - NONE of the Properties name/openurl/title were assigned to the ChildWindow ","Choose another property to Perform Action on opened Child Window"
Else
Reporter.ReportEvent micPass,"Recognized the Child Window by using the property '" & SetProperty & "' ","Performs an Action MAXIMIZE on opened Child Window"
SetProperty1=SetProperty & ":=" & optsBrwName
Dim hwndBrw, hwndWindow
hwndBrw = Browser(SetProperty1).GetROProperty("hwnd") Const GA_ROOT = 2
Extern.Declare micLong,"GetMainWindow", "user32" ,"GetAncestor",micLong, micLong hwndWindow = Extern.GetMainWindow(hwndBrw, GA_ROOT) Window("hwnd:=" & hwndWindow).Maximize
End If
Set BrwDesc = Nothing
End Function
-------------------------------------------------
'Open Browser Count.
-------------------------------------------
Function fGetBrowsersCount()
Set ObjIExpl = Description.Create
ObjIExpl("micclass").value = "Browser"
Set ObjIExplColl = Desktop.ChildObjects(ObjIExpl)
fGetBrowsersCount = ObjIExplColl.Count
End Function
Functionality: Compare the data in PDF, using VB script
Step 1:
First Create a object for clipboard
Set objCB = CreateObject("Mercury.Clipboard")
objCB.Clear
Step 2:
If Browser("title:=https://Browser name").ActiveX("acx_name:=Adobe PDF Reader").WinObject("text:=AVPageView").Exist Then
Browser("title:=https://Browser name").ActiveX("acx_name:=Adobe PDF Reader").WinObject("text:=AVPageView").Type micCtrlDwn + "a" + micCtrlUp
Browser("title:=https://Browser name").ActiveX("acx_name:=Adobe PDF Reader").WinObject("text:=AVPageView").Type micCtrlDwn + "c" + micCtrlUp
If Browser("title:=https://Browser name").Dialog("nativeclass:=#32770").Exist then
Browser("title:=https://Browser name").Dialog("nativeclass:=#32770").Winbutton("text:=OK").Click
End If
Step 3: Now you search the text you want to check in PDF
strUID = "Help"
PDFTxt = Instr(1, objCB.GetText, strUID)
If (PDFTxt > 0) Then
reporter.ReportEvent micPass, "id exists", "id there"
Else
reporter.ReportEvent micPass, "id not exists", "id not there"
End If
End if
Browser("title:=https://Browser name").close
Set objCB = Nothing
Monday, November 22, 2010
Functionality: Select an environemtn by using dot net factory method
Set objEnviForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form")
Set objEnvFormRdgp = DotNetFactory.CreateInstance("System.Windows.Forms.GroupBox")
Set objEnvFormRB1 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton")
Set objEnvFormRB2 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton")
Set objEnvFormRB3 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton")
Set objEnvFormRB4 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton")
Set objEnvFormRB5 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton")
Set objEnvFormOKButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button")
Set objEnvFormCANCELButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button")
Set objButtonFlatStyle = DotNetFactory.CreateInstance("System.Windows.Forms.FlatStyle")
Set objButtonDialogResult=DotNetFactory.CreateInstance("System.Windows.Forms.DialogResult")
Set formStartPos = objEnviForm.StartPosition
With objEnviForm
.Text = "AES Automation"
.TopMost = True
.FormBorderStyle = .FormBorderStyle.FixedToolWindow
.Size = DFGetSize(500,150)
objEnvFormRdgp.Controls.Add objEnvFormRB1
objEnvFormRdgp.Controls.Add objEnvFormRB2
objEnvFormRdgp.Controls.Add objEnvFormRB3
objEnvFormRdgp.Controls.Add objEnvFormRB4
objEnvFormRdgp.Controls.Add objEnvFormRB5
objEnvFormRdgp.Location = DFGetPont(25,10)
objEnvFormRdgp.Size = DFGetSize(350,80)
objEnvFormRdgp.Text= "Select AES Environment"
objEnvFormRdgp.TabIndex=0
objEnvFormRB1.Location = DFGetPont(30,15)
objEnvFormRB1.Size = DFGetSize(70,20)
objEnvFormRB1.Name = "RadioBox1"
objEnvFormRB1.Text = "&UAT"
objEnvFormRB2.Location = DFGetPont(30,40)
objEnvFormRB2.Size = DFGetSize(70,20)
objEnvFormRB2.Name = "RadioBox2"
objEnvFormRB2.Text = "&SIT"
objEnvFormRB3.Location = DFGetPont(160,15)
objEnvFormRB3.Size = DFGetSize(70,20)
objEnvFormRB3.Name = "RadioBox3"
objEnvFormRB3.Text = "&PFIX"
objEnvFormRB4.Location = DFGetPont(160,40)
objEnvFormRB4.Size = DFGetSize(70,20)
objEnvFormRB4.Name = "RadioBox4"
objEnvFormRB4.Text = "PRO&D"
objEnvFormRB5.Location = DFGetPont(270,15)
objEnvFormRB5.Size = DFGetSize(70,20)
objEnvFormRB5.Name = "RadioBox5"
objEnvFormRB5.Text = "&MIT"
objEnvFormOKButton.Location = DFGetPont(400,15)
objEnvFormOKButton.Size = DFGetSize(70,20)
objEnvFormOKButton.Name = "Button1"
objEnvFormOKButton.FlatStyle = objButtonFlatStyle.Popup
objEnvFormOKButton.DialogResult = objButtonDialogResult.OK
objEnvFormOKButton.Text = "&OK"
objEnvFormOKButton.TabIndex = 1
objEnvFormCANCELButton.Location = DFGetPont(400,40)
objEnvFormCANCELButton.Size = DFGetSize(70,20)
objEnvFormCANCELButton.Name = "Button2"
objEnvFormCANCELButton.FlatStyle = objButtonFlatStyle.Popup
objEnvFormCANCELButton.Text = "&Cancel"
.AcceptButton = objEnvFormOKButton
.CancelButton = objEnvFormCANCELButton
.Controls.Add objEnvFormRdgp
.Controls.Add objEnvFormOKButton
.Controls.Add objEnvFormCANCELButton
.StartPosition = formStartPos.CenterScreen
End With
i=0
Do
objEnviForm.ShowDialog
objEnviForm.Activate
strSelectChoice = ""
If
objEnvFormRB1.Checked Then
strSelectChoice = "UAT"
ElseIf objEnvFormRB2.Checked then
strSelectChoice = "SIT"
ElseIf objEnvFormRB3.Checked then
strSelectChoice = "PFIX"
ElseIf objEnvFormRB4.Checked then
strSelectChoice = "PROD"
ElseIf objEnvFormRB5.Checked then
strSelectChoice = "MIT"
Else strSelectChoice= "No Option is Selected"
End If
If UCase(objEnviForm.DialogResult)="CANCEL" Then
' MsgBox "You Cancelled the form"
strSelectChoice = "CANCEL"
i=1
ElseIf strSelectChoice= "No Option is Selected" Then
MsgBox "You have not selected any option. Please Choose one"
i=0
Else
' MsgBox strSelectChoice
i=1
End If
Loop Until i=1
Set objEnviForm = Nothing
Set formStartPos =Nothing
Set objButtonFlatStyle = Nothing
Set objButtonDialogResult = Nothing
Set objEnvFormRdgp = Nothing
Set objEnvFormRB1 = Nothing
Set objEnvFormRB2 = Nothing
Set objEnvFormRB3 = Nothing
Set objEnvFormRB4 = Nothing
Set objEnvFormRB5 = Nothing
Set objEnvFormOKButton = Nothing
Set objEnvFormCANCELButton = Nothing
SelectEnv = strSelectChoice
End Function
Function DFGetSize(x,y)
Set DFGetSize = DotNetFactory.CreateInstance("System.Drawing.Size","System.Drawing",x,y)End Function
Function DFGetPont(x,y)
Set DFGetPont = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
End Function
Functionality: Is to CLOSE Browser/PDFChildWindow'Parameters: ANY Property - title OR openurl OR name'
'Purpose: Is to CLOSE Browser/PDFChildWindow'Parameters: ANY Property - title OR openurl OR name'______________________________________________________
Function Close_ANY_Browser (optsBrwName)
Set BrwDesc = Description.Create()
BrwDesc("micclass").Value = "Browser"
rcBrwCount = fGetBrowsersCount()-1
UnKnown_hwnd=Browser("CreationTime:="& rcBrwCount).GetROProperty("hwnd")
Get_title= Window("hwnd:="& UnKnown_hwnd).GetROProperty("title")
Get_name = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("name")
Get_openurl = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("openurl")
If Get_title = "" AND Get_name = "" Then
SetProperty = "openurl"
Else
SetProperty = "title" End If
BrwDesc(SetProperty).Value = optsBrwName
If Get_title ="" AND Get_name = "" AND Get_openurl="" Then
Reporter.ReportEvent micFail,"DID NOT Get Property Values for an opened Child Window - Properties name/openurl/title were NOT assigned to the ChildWindow ","Choose another property to Perform Action - CLOSE on opened Child Window"
Else
Reporter.ReportEvent micPass,"Recognized the Child Window/Browser by using the property '" & SetProperty & "' ","Performs an Action CLOSE on opened Child Window"
SetProperty1=SetProperty & ":=" & optsBrwName
Browser(SetProperty1).Close
If NOT Browser(SetProperty1).Exist(0) Then
Close_ANY_Browser = True
End If
Set BrwDesc = Nothing
End If
End Function
-----------------------------------------
Function fGetBrowsersCount()
Set ObjIExpl = Description.Create
ObjIExpl("micclass").value = "Browser"
Set ObjIExplColl = Desktop.ChildObjects(ObjIExpl)
fGetBrowsersCount = ObjIExplColl.Count
End Function
----------------------------------------------------------
Functionality: It Works for IE6 IE7 and IE8 - Maximize Browser
Functionality: It Works for IE6 IE7 and IE8 - Maximize Browser
______
Function BrowserMaximize (optsBrwName)
Set BrwDesc = Description.Create()
BrwDesc("micclass").Value = "Browser"
rcBrwCount = fGetBrowsersCount()-1
UnKnown_hwnd=Browser("CreationTime:="& rcBrwCount).GetROProperty("hwnd")
Get_title= Window("hwnd:="& UnKnown_hwnd).GetROProperty("title")
Get_name = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("name")
Get_openurl = Window("hwnd:="& UnKnown_hwnd).GetRoProperty("openurl")
If Get_title = "" AND Get_name = "" Then
SetProperty = "openurl"
Else
SetProperty = "title"
End If
BrwDesc(SetProperty).Value = optsBrwName
If Get_title ="" AND Get_name = "" AND Get_openurl="" Then
Reporter.ReportEvent micFail,"DID NOT Opens the Child Window - NONE of the Properties name/openurl/title were assigned to the ChildWindow ","Choose another property to Perform Action on opened Child Window"
Else
Reporter.ReportEvent micPass,"Recognized the Child Window by using the property '" & SetProperty & "' ","Performs an Action MAXIMIZE on opened Child Window"
SetProperty1=SetProperty & ":=" & optsBrwName
Dim hwndBrw, hwndWindow
hwndBrw = Browser(SetProperty1).GetROProperty("hwnd")
Const GA_ROOT = 2
Extern.Declare micLong,"GetMainWindow", "user32" ,"GetAncestor",micLong, micLong
'Get the main IE window handle
hwndWindow = Extern.GetMainWindow(hwndBrw, GA_ROOT)
Window("hwnd:=" & hwndWindow).Maximize
End If
Set BrwDesc = Nothing
End Function
------------------------------------------------------------
Function fGetBrowsersCount()
Set ObjIExpl = Description.Create
ObjIExpl("micclass").value = "Browser"
Set ObjIExplColl = Desktop.ChildObjects(ObjIExpl)
fGetBrowsersCount = ObjIExplColl.Count
End Function
---------------------------------------
Functionality: Enter the login id and password using the XML file
Functionality: Enter the login id and password using the XML file:-
-------------------------------------------------------------------------
Public Function LoginUserInfo()
If fso.FileExists("C:\Login_AES.xml") Then
'Creates object for "Msxml2.DOMDocument"
'Set xmlDoc = CreateObject("Msxml2.DOMDocument")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load("C:\Login_AES.xml")
Set ENVnode = xmlDoc.getElementsByTagName("ENV")
Set IDnode = xmlDoc.getElementsByTagName("ID")
Set PSWDnode = xmlDoc.getElementsByTagName("PSWD")
ENVlength=ENVnode.length
IDlength=IDnode.length
PSWDlength=PSWDnode.length
Counter=1 'Loop to retrive xml items.
for Counter=0 to ENVlength-1
ENVitem=ENVnode.item(Counter).Text
IDitem=IDnode.item(Counter).Text
PSWDitem= PSWDnode.item(Counter).Text
If (LEnv = ENVitem) Then
Environment.Value("ENV") = ENVitem
Environment.Value("UserID")=IDitem
Environment.Value("PSWD") = PSWDitem
ENV = Envitem
UserID = IDitem
PSWD = PSWDitem
Exit For
End If
Next
End If
End Function
Monday, November 15, 2010
Functionality: Create 5 digit random number in vb script
'**************************************************************
Public Function CreateFiveDigitRandomId()
tTime = replace(Time, ":", "")
tLen = Len(tTime) - 2
tTime = Trim(left(tTime, tLen))
intLowNumber = Right(tTime, 2)
tLen = Len(tTime)
If tLen > 5 Then
tTime = Trim(Right(tTime, 5))
End If
intHighNumber = tTime intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
If Len(intNumber)> 4 Then
intNumber = Left(intNumber, 4)
End If
dtDay = Day(Date)
If len(dtDay) = 2 Then
dtDay = Right(dtDay, 1)
intNumber = intNumber & dtDay
Else
intNumber = dtDay & intNumber
End If
glbRandId = intNumber
End Function
'********************************************************************
Public Function SelectWebContol(strWebControl,strBrowserName,strPageName,strLogcalName,strIndex ,strValue,strLogicalValue)If strIndex = "" Then
strIndex = "0"
End If
strWebControl = UCASE (strWebControl)Select Case strWebControl
Case "WEBEDITBOX"
Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).WebEdit("name:=" & strLogcalName, "index:=" & strIndex).Set strValue Exit Function
Case "WEBCHECKBOX" If strLogicalValue <> "" Then Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).WebCheckBox("name:=" & strLogcalName,"index:=" & strIndex,"value:=" & strLogicalValue).Set strValue
Exit Function
End If
Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).WebCheckBox("name:=" & strLogcalName,"index:=" & strIndex).Set strValue
Exit Function
Case "WEBLIST"
Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).WebList("name:=" & strLogcalName, "index:=" & strIndex).Select strValue Exit Function Case "WEBRADIOGROUP" Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).WebRadioGroup("name:=" & strLogcalName, "index:=" & strIndex).Select strValue
Case "IMAGE"
If Not Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).Image("alt:=" & strLogcalName,"index:=" & strIndex).Exist(3) Then Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).Image("file name:=" & strLogcalName,"index:=" & strIndex).Click Exit Function End If Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).Image("alt:=" & strLogcalName,"index:=" & strIndex).Click
Exit Function
Case "WEBBUTTON"
Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).WebButton("name:=" & strLogcalName, "index:=" & strIndex).Click
Exit Function
Case "WEBMSGBOX"
If Browser("name:=" & strBrowserName).Dialog("nativeclass:=#32770").Exist(5) Then Browser("name:=" & strBrowserName).Dialog("nativeclass:=#32770").WinButton("text:=" & strLogcalName,"index:=" & strIndex).Click
End If
Exit Function
Case "LINK" Browser("name:=" & strBrowserName ).Page("title:=" & strPageName).Link("innertext:=" & strLogcalName,"index:=" & strIndex).Click Exit Function Case Else Reporter.ReportEvent micFail, "Operation on the Control", " Operation on the web control" & strWebControl & " is failed" End SelectEnd Function
*************************************************************************
Class QTPStartStop
Private Sub Class_Terminate()
MsgBox "QTP Terminated"
End Sub
End Class
'crate an object of that class at the start of the Script
Dim QtpStop
Set QtpStop = New QTPStartStop
******************************************************************************
Just double click the file, your all temp files will get deleted directly..
'===DeleteTempFiles.vbs==='
Const TemporaryFolder = 2 'for GetSpecialFolder
set fso = createobject("scripting.filesystemobject")
'init an empty array (ubound will be -1)... ' 'we use an array and store the file objects. 'this avoids any problems with altering the 'contents of the Files collections while they 'are being iterated. ' arFiles = array() count = -1
'get the path to the temp folder ' tempdir = fso.GetSpecialFolder(TemporaryFolder)
'load the (global scope) arFiles 'SelectFiles calls itself recursively 'for SubFolders ' SelectFiles tempdir msgbox count+1 & " files found" 'now do the actual deletes. the error trap 'is in case any are in-use... ' dcount = 0 for each file in arFiles on error resume next file.delete true if err.number = 0 then dcount = dcount + 1 err.clear on error goto 0 next
'now go back and delete empty folders 'below the temp folder
DeleteEmptyFolders tempdir,false
'comment out for "silent" operation, 'or add support for a "/s" command-line switch. ' msgbox count+1 & " files found, " & dcount & " deleted."
sub SelectFiles(sPath)
'select files to delete and add to array... ' set folder = fso.getfolder(sPath) set files = folder.files
for each file in files count = count + 1 redim preserve arFiles(count) set arFiles(count) = file next
for each fldr in folder.subfolders SelectFiles fldr.path next
end sub
sub DeleteEmptyFolders(sPath,bDeleteThisFolder)
set folder = fso.getfolder(sPath)
'recurse first... ' for each fldr in folder.subfolders DeleteEmptyFolders fldr.path,true next
'if no files or folders then delete... ' 'bDeleteThisFolder is false for 'the root of the subtree, and true for 'sub-folders (unless you want to delete 'the entire subtree if it is empty). ' if (folder.files.count = 0) and _ (folder.subfolders.count) = 0 and _ bDeleteThisFolder then folder.delete exit sub end if
end sub ' '===end-script===