WORKING WITH QTP

TestEveryThinG

Delete Cookies and Temprary internet files VB QTP

Posted by rajivkumarnandvani on April 17, 2009

rem ********************************

rem delete cookies

call fn_DeletesubFolderAndFiles(“C:\DOCUME~1\%USERNAME%\Cookies”)

rem *********************************

rem rem delete Temporary internet files

call fn_DeletesubFolderAndFiles(“C:\DOCUME~1\%USERNAME%\Locals~1\Tempor~1”)

rem ***********************************

REM *************************************************************************

REM Function fn_DeletesubFolderAndFiles(path)

Rem this Function delete the files & subfolder under the specified path

REM Input spath := Files path or parent Folder path

REM Output(ReturnType) := None

REM Note := IF file Protected then it will not delete without giving Error

REM Created: 17/April/2009 Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY

REM *************************************************************************

Public Function fn_DeletesubFolderAndFiles(spath)

on Error Resume Next

rem Create File System object

set objFileSystem = CreateObject(“Scripting.FileSystemObject“)

rem Create Window Shel object

Set objWshShell = CreateObject(WScript.Shell“)

Rem get Folderpath under which file present

Set objoFolder = objFileSystem.GetFolder(objWshShell.ExpandEnvironmentStrings(spath))

rem get count the files under the folder and loop run for delete the files

For Each oFile In objoFolder.files

On Error Resume Next

objFileSystem.DeleteFile oFile

Err.clear

Next

rem get count the subfolders under the folder and loop run for delete the subfolders

For Each oSubFolder In objoFolder.SubFolders

On Error Resume Next

objFileSystem.DeleteFolder oSubFolder

Err.clear

Next

rem clear the object

set objFileSystem = nothing

set objWshShell = nothing

set objoFolder = nothing

Err.clear

End function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: