Ask a Question

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

nish_b
Contributor

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 5
vthomeschoolmom
Super Contributor

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

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
Community Hero

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

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

AlexKaras
Community Hero

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

Hi,

 

aqFileSystem.FindFiles() ?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
tristaanogre
Community Hero

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

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

 

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
vthomeschoolmom
Super Contributor

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

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

cancel
Showing results for 
Search instead for 
Did you mean: