Forum Discussion

nedbacan's avatar
nedbacan
Frequent Contributor
5 years ago

Find a specific file when the folder get created during run time.

Please need help, I am testing this web application that creates a dynamic folder every time an image is displayed within the software, Here are my test steps. 1) select the customer. 2) select the...
  • Marsha_R's avatar
    Marsha_R
    4 years ago

    first you look for the period in the file name

    var MyPeriodLocation= aqString.Find(MyImageNumber,".",0)

     

    now you get the first part of the file name, up to the period

    var NoMoreJPG= aqString.Substring(MyImageNumber,0,MyPeriodLocation)

     

    so your folder name is 

    MyFolderName = "C:\Storage\cache\" + NoMoreJPG

     

    Here's a good reference for operations that you can do with strings.  When you get more experience with it, you can combine some of the steps but it's good to do them one step at a time if you aren't sure of the answers.  Sometimes I will also add a log message after each step to print out the answer and make sure it's doing what I meant it to do.  

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/methods.html

     

  • nedbacan's avatar
    nedbacan
    4 years ago

    Great, I was able to get the filename without the file extension.  Kudos to you !!!!

     

    Thank you very much. 

     

  • AlexKaras's avatar
    AlexKaras
    4 years ago

    Hi,

     

    MyFolderName = "C:/Storage/octCache/" + NoMoreJPG;

    Try

    var MyFolderName = "C:\\Storage\\octCache\\" + NoMoreJPG;

    Does it help?

     

    P.S. BTW, your initial code works fine for me using JScript. Is your code on JScript or JavaScript?

     

  • AlexKaras's avatar
    AlexKaras
    4 years ago

    Hi,

     

    I need to verify imagesnap.jpg exist within the folder MyFolderName.

    Use aqFile.Exists() method.

     

  • AlexKaras's avatar
    AlexKaras
    4 years ago

    Hi,

     

    The folder name will be different on every run so the pathname cannot be hardcoded.

    Make it dynamic. Something like this:

    var MyFolderName = "C:\\Storage\\octCache\\" + NoMoreJPG + "\\";

    var FileFullPath = MyFolderName + "imagesnap.jpg";

    if (aqFile.Exists(FileFullPath))

      ...

     

     

  • nedbacan's avatar
    nedbacan
    4 years ago

    Thank you !!