Forum Discussion

rachel_dunlop's avatar
rachel_dunlop
Occasional Contributor
12 years ago

How to use wildcards in a filename?

Hi all,

I've just started using TestComplete and I'm a bit stuck with something.

I need to automate an action where the application imports a file. So far so good. However the filename will change with different versions (version number is in the filename.)

How can I make sure the test can pick up the file each time if part of the filename changes?

I've tried playing with the * and ? wildcards but I mustn't be using them right.



This is a keyword test and the step looks like this:

Item Operations Value

dlgOpen OpenFile C:\Folder\filename1.23.4567.8910.Blah.zip



Its the .8910 part of the filename which will change (in the short term at least).



Can someone please help?

17 Replies

  • TonyMro's avatar
    TonyMro
    Occasional Contributor
    "What
    I'm looking for is just a simple way to pickup a file called
    "filename1.95.****.zip"  reliably every time the test is executed"




    Hi Rachel,



    Take a look at the aqFileSystem.FindFiles method and the example code for it in TestComplete's help. This method can be used to search through a directory for a file name that meets the specified criteria, and it accepts wildcard characters. If it finds any files that match the criteria, it returns them in an aqObjIterator object that can be evaluated to determine the exact name of the file that you can then use in your test script.



    Good luck...

  • aniket's avatar
    aniket
    Occasional Contributor
    I might be little off the topic but you can have your latest build copied to a constant location with same name. Your build team can help you with that. It is not the big effort to copy build at a folder say AutoTest with name latest.exe
  • rachel_dunlop's avatar
    rachel_dunlop
    Occasional Contributor
    Hi all, thanks for all the posts! Great stuff!

    I'm hoping to have a training day tomorrow or early next week to look at these suggestions and will probably have many questions then!

    Watch this space :D
  • rachel_dunlop's avatar
    rachel_dunlop
    Occasional Contributor


    Alternatively, is there a way to know the build or version number ahead of time? You can then use concatenation to build the correct file name.





    @Jeff, yes I've found I can grab the version number from the application under test! Breakthrough! I've got my test grabbing that info and putting it into a variable

    Next step, how do I use concatenation in a keyword test? Because once I can do that I can cut out the build number into a variable with the static part of the filename (I hope) giving me the complete filename dynamically!



  • rachel_dunlop's avatar
    rachel_dunlop
    Occasional Contributor
    Hi Rachel,



    one way of doing it is using vbscript string concatenation,



    C:\Folder\filename1.23.4567.8910.Blah.zip



    String1="C:\Folder\filename1.23.4567."

    String2=build version

    String3="Blah.zip"



    Finally, the file name will be



    FileName=String1 & String2 & String3



    Here, the file name is constructed dynamically in run time.



    Pls let me know if this solution helps you or you are looking for something different.









    @Murali, Further investigation on my part shows I can in fact get a string which contains the build number dynamically during the test.

    Our test lead would prefer us to use javascript not vb, do you know if that makes a difference?

    Now its just actually piecing the bits together in TestComplete that I need to work out.



  • rachel_dunlop's avatar
    rachel_dunlop
    Occasional Contributor
    Thanks all, eventually I have got it!

    I have two scripts as part of the test suite, one takes the full version name from within the application as a string, splits the string into various parts and then reassembles the bits I need to create the filename and another which reads the country code of the database and sends that  value to the other script to complete the filename (another level of complexity I forgot to mention!)



    Thanks very much for helping me think it through and suggesting I get my feet wet in the code!