Forum Discussion

drishti_Xcell's avatar
drishti_Xcell
Regular Visitor
2 years ago

How to create a new file with new name each time?

I am new to Testcomplete and I am trying to automate a desktop application. The test case I am trying to automate is to create a new file.

For eg- I create a new file "Testfile1". When I run the test It will again create the same file and I will get a message saying "Testfile1"already exists. Do you want to replace "Testfile1"? How I can create my test so each time I run the test it creates a new file with new name for eg- Testfile2, Testfile3 and so on. Thanks in advance.

2 Replies

  • MW_Didata's avatar
    MW_Didata
    Regular Contributor

    I created a small script that checks if a file exists and then deletes it. if its just for testing maybe you could also just delete the previous file.

    That way you will always create the same file and delete it.

    Script created in vbs so might not work completely for you

     

    Function Deletefile(path, file, ext)

        'This function checks if the (file) exists, if zo it deletes the file'
        Set foundFiles = aqFileSystem.FindFiles((path), (file) & (ext))
          If Not foundFiles Is Nothing Then
             While foundFiles.HasNext
              Set aFile = foundFiles.Next

    '(maybe you could add another log message here to see if file was found)'
              'This function deletes the (file) in the directory (path)'
              aqFileSystem.DeleteFile((path) & aFile.name)
              Log.Message aFile.name & " is deleted"
           Wend
          Else
               Log.Warning (file) & (ext) & " kan niet worden verwijderd omdat " & (file) & (ext) & " niet bestaat"
         End If

    End Function

     

     

    (sorry for using spaces before the code, I dont know how to import code layout)