Forum Discussion

rhu's avatar
rhu
Contributor
2 years ago

How to use wildcards in aqfilesystem to move and rename a file

I download files from a webpage. This filenames  are individual(and i do not know them before downlaoding)  like e.g.  "response_1655109976711.json" , "response_1657109876736.json" 

 

What i want to do:
i want to copy the created file to the project Path folder and later on compare it with an existing file.
The problem seems to be that I can not rename the file correctly because wildcards do not work.

 

If I use a hardcoded filename the copy and rename in the script is working.
But how to use placeholders?
Example for such a script with a hardcoded name (working):

function MoveAndRenameFileExample()
{
var OldPath = "C:\\Users\\testuser\\Downloads\\response_1655109976711.json";
var NewPathMove = Project.Path+"Example.json";
var RenameOnCollision = false
aqFileSystem.RenameFile(OldPath, NewPathMove, RenameOnCollision) ;
}

For wildcards I  tried with the following lines
var OldPath = "C:\\Users\\testuser\\Downloads\\*.json";
or
var OldPath = "C:\\Users\\testuser\\;response_?????????????.json


But  I always get an error (at renaming).

Alternatively it would also help me if sowmebody can tell me how I can get the complete path and filename (like C:\\Users\\testuser\\Downloads\\response_1655109976711.json) of the last downloaded file so that i can use it as e.g. last operating result and then moves/rename it?

i am now able to find the file using https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfilesystem/findfiles.html
but still have the problem how to move and rename it.



3 Replies