Forum Discussion

khushbupatel's avatar
khushbupatel
Occasional Contributor
8 years ago

How to read filenames which are randomly generated?

Hello,

 

I am pretty new to testcomplete and looking for some guideline on how to get filenames which are created with random names?

Our application generates pdf reports and give them random names Ex. tmpD3C6.pdf

 

Thank you!

5 Replies

  • Hey khush,

    great to see you here in the forum!

    What do you want to do with those files? Just check if they are present or open them to see their contents?

    If you just want to check if the files are present on the disk, you can do it as follows:

    Create a Script Test and paste the following code in it:

    aqObject.CompareProperty(aqFileSystem.Exists(C:\Path\To\Your\Report.pdf), cmpEqual, true);

    If you wish to check the file contents, you may find the File Checkpoint operation useful.

     

    Either way, you need to find some way to identify the file you need. Here are some ideas to do so:

    1. Ask your developers if there is some logic behind the filenames
    2. Delete all files in the report folder at the beginning of the test using the DeleteFile-Method and a for-loop or the DeleteFolder-method. In that case, there should be only the current report in that folder.

    Greetings,

    vatbub

    • khushbupatel's avatar
      khushbupatel
      Occasional Contributor

      Thanks for your detailed reply. I want to read the content of PDFs and compare them with baseline files but I do not want to use File Checkpoints. I have figured out that part but only need to figure out reading random name of PDFs. I was thinking about it and so far what I have done is when developers generate report, they automatically open them so I will Save as file and give it a name I want and then read them. 

       

      I will see how it goes along the road.

       

      Again thank you !

      • vatbub's avatar
        vatbub
        Contributor

        Hi khus,

        what about deleting all files from the directory prior to starting the test? Then, you should only find your newly generated report in that directory.

        Greetings,

        vat