Forum Discussion

edgarh88's avatar
edgarh88
New Contributor
3 years ago
Solved

How to Validate recently downloaded output Excel Files

Hi all,    I´m currently working in some scenarios which requires to input some information into an Excel file, upload this file into the system, wait for the system to process such file and after ...
  • ebarbera's avatar
    3 years ago

    Hello edgarh88 - 

     

    This could be accomplished by using a variable in the path for the excel file - are you currently using keyword tests or scripts in TestComplete?

     

    Could you show me where you have the path and i could explain how best to do this?

     

    Thanks, 


    Emma

  • chriscc's avatar
    3 years ago

    Hi edgarh88, @

     

    To expand upon Emma's (ebarbera) suggestion, you could get the most recently created file from a directory.  This function will allow you to pass in the directory and file extension and will return the most recent created file path.  I added a test function below to show how to pass in your parameters.  I hope this helps.

     

        function getMostRecentCreatedFile(directoryPath, searchPattern)

        {

          var newestFilePath = "";

          var previousCreationTime = "1/1/1900";

          try

          {

            var files = aqFileSystem.FindFiles(directoryPath, searchPattern, false);

            if (files != null)

            {         

              while(files.HasNext())

              {

                var file = files.Next();

                var creationTime = aqFile.GetCreationTime(file.Path);

                if (aqDateTime.Compare(creationTime, previousCreationTime) == 1)

                {

                  previousCreationTime = creationTime;

                  newestFilePath = file.Path;

                }

              }

            }

          }

          catch(e)

          {

            Log.Error("Exception in getMostRecentCreatedFile", e.descrpition);

          }

          //

          return newestFilePath;

        }

     

     

        function testGetFile()

        {

          var filePath = getMostRecentCreatedFile("C:\\Users\\herrerae\\Downloads", "*.xlsx");

        }