Powered by: Dharamveer Saxena

Wednesday, November 25, 2009

Testcomplete: To check if the file exists and to delete a file if it exists

Below is the vbscript code that can be used to check if the file exists on system or not

'In below examples: path is the path of file like "c:\text.txt"

Sub Main
set fs=createObject("Scripting.FileSystemObject")
If not fs.FileExists(path) Then
Log.Message("Fail: file does not exist")
Else
Log.Message("Pass: File exists")
End If

End Sub

Below is the code to delete a file


Sub Delete

set fs=createObject("Scripting.FileSystemObject")
If not fs.FileExists(path) Then
Else
fs.deletefile(path)
End If

End sub

3 comments:

  1. Hi

    I want to know how to extract the test script name currently executing.
    Project["TestItems"]["Current"].Name property gives an error as "Object required".
    please help me on this or please provide some other solution to grab currently running test script name.
    i am using testcomplete 6.0 version

    Thanks
    Nivedita

    ReplyDelete
  2. Fyi, these have been in TC for awhile now:

    aqFile.Delete();
    aqFile.Exists();

    aqFile is a new object available in TC v7.x

    ReplyDelete