Forum Discussion

Dk_3108's avatar
Dk_3108
Occasional Contributor
3 years ago

How Identify a file name with time stamp in Test complete using Python Scripts

Hi ,
I have a scenario to validate whether the downloaded file exists in a folder ,I have used the below script to validate whether the file name exist or not.

However the downloaded file has a name reference with date and time as a result the below script is failing to identify the file name since the date and timestamp changes whenever the respective file is downloaded.

 

Can someone help me on this as i am new to Test complete and Python.

 

 

def FileExist():
filepath="C:\\Users\\dkaliyugavarathan\\Downloads\\Order_Extract_Export_2022-03-10_20-42-32.csv"
if aqFileSystem.Exists(filepath):
Log.Message("Order extract export file downloaded successfully! ")
elif not aqFileSystem.Exists(filepath):
Log.Message("Order extract export file does not exists")

 

 

Thanks in advance!..

3 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    What I would do is have a string variable with the front part of the file path in it

    mypath1 = "C:\\Users\\dkaliyugavarathan\\Downloads\\Order_Extract_Export_"

     

    and then have a second string variable with the date part of the file path in it  (you will have to build this)

    mypath2 = "2022-03-10_20-42-32"

     

    so finally you can have the actual file path

    filepath = mypath1 + mypath2

     

    You can build what you need for the date part using these 

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/index.html

    https://support.smartbear.com/testcomplete/docs/scripting/working-with/strings/python.html

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Another possible option might be to delete all Order_Extract_Export_*.csv files from the download folder just before downloading, download and then search for all Order_Extract_Export_*.csv files. If only one file is found than with a high probability this is the file you are looking for. If more files are found you may additionally sort them by date/time and use the most recent one.

     

  • sonya_m's avatar
    sonya_m
    SmartBear Alumni (Retired)

    Thanks Marsha and Alex!

     

    Hi Dk_3108 , please mark the best reply as a solution!