Ask a Question

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

rhu
Contributor

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.htm...
but still have the problem how to move and rename it.



3 REPLIES 3
Marsha_R
Community Hero

Use log.message right after you get OldPath and let's see what's actually in there


Marsha_R
[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

Hi,
i am using log.message and i can see the name of the file (e.g. response_1655186284821.json) in the log.
But how can i use that information to rename/move the file or in a rename or move script or to use it with filecompare?

Marsha_R
Community Hero

This looks like it would work for you. The result object would have only your one file in it and you could get the name from there.

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfilesystem/findfiles.htm...


Marsha_R
[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
cancel
Showing results for 
Search instead for 
Did you mean: