Forum Discussion

nish_b's avatar
nish_b
Contributor
5 years ago

aqFileSystem.Exists: Is there a way to add wildcard characters in the filename?

 

Hi,

 

After I click on Download Excel button present in my application., I have a function that has to wait until download finishes using "aqFileSystem.Exists(filenameWithPath)" as a check. The download file gets downloaded in my Download folder. Let's say my file name is ReportName

 

So, my code looks something like this:

 

aqFileSystem.Exists("C:\\Users\\test\\Downloads\\ReportName.xlsx"); 

 

The above code works fine only 1st time ReportName gets downloaded. What if I run my script again and the file downloads? It actually appends (1)  and then next time again (2) and so to the filename. So it becomes ReportName (1).xlsx , ReportName (2).xlsx and so on. So in this scenario above code will fail.

 

To avoid the above issue, I tried doing this (hoping wildcard character match works):

aqFileSystem.Exists("C:\\Users\\test\\Downloads\\ReportName*.xlsx"); 

 

But it didn't work. It returns false, although the file is downloaded and present in the path.

 

Please help.

5 Replies

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      FindFiles could work.  Then if the array returned has a length greater than 0, at least one file exists.

       

       

      • vthomeschoolmom's avatar
        vthomeschoolmom
        Super Contributor

        If this were me, I would not love this check. This check - finding any file that may have been downloaded, does not adaquately consider whether or not what is being found is THIS file from THIS run. Thus the method suggested. ymmv

  • I can't answer the question as asked having never come across it. As a matter of habit, what I would do in script would be

    - do the stuff that generates the download.

    - check that the downloaded file exists.

    - clean up (delete) the downloaded file.

     

    Thus next run, the file does not have a counter appended to it. 

     

    One option. Hopefully someone can chime in on your question as asked.

    • LinoTadros's avatar
      LinoTadros
      Community Hero

      The checking for a File existence with a wildcard is a bad practice.

      As vthomeschoolmom  said the right way to do this is to delete the file during each run after exists return true.

      Cheers

      -Lino