Forum Discussion

Herman's avatar
Herman
Contributor
15 years ago

The count property of the object "aqFileSystem.GetFolderInfo(FolderName).Files.Count" is reported to be "unknown".

I'm using DelphiScript for testing some applications. I use the procedure shown below to check if the number of files and subfolders in a tested folder is as expected. The problem with this procedure is that TestComplete reports that "Count" is unknown. This error occurs not always. It is not clear to me what to do to make sure the procedure is always working (not complaining about the unknown "Count").



procedure TestNoOfFilesAndSubFoldersInFolder(FolderName, ExpectedNoOfFiles, ExpectedNoOfSubFolders);

var ActualNo;

begin

Log
.Message(FolderName);

Log.Warning('The Count property is not recognized');

if FolderExists(FolderName) then

begin

ActualNo := aqFileSystem.GetFolderInfo(FolderName).Files.Count;

if ActualNo = ExpectedNoOfFiles then

LogSuccess(aqString.Format('The expected no. of files (%d) was found in folder %s', ExpectedNoOfFiles, FolderName))

else

LogWarning(aqString.Format('The no. of files (%d) differs from the expected no. (%d) for folder %s', ActualNo, xpectedNoOfFiles, FolderName));

ActualNo := aqFileSystem.GetFolderInfo(FolderName).SubFolders.Count;

if ActualNo = ExpectedNoOfSubFolders then

LogSuccess(aqString.Format('The expected no. of subfolders (%d) was found in folder %s', ExpectedNoOfSubFolders, FolderName))

else

LogWarning(aqString.Format('The no. of subfolders (%d) differs from the expected no. (%d) for folder %s', ActualNo, ExpectedNoOfSubFolders, FolderName));end;



end;


;

7 Replies

  • I forget to mention the procedures LogSuccess and LogError.



    LogSuccess is calling Log.Message setting the background color to green.

    LogError is calling Log.Error setting the background color to red.



    Herman
  • Hi Herman,


    We've reproduced this incorrect behavior, and we'll fix it. The error occurred when there were no files within the FolderName folder.


    If this is your case, modify your script so that there're the following lines instead of just one "ActualNo := aqFileSystem.GetFolderInfo(FolderName).Files.Count;" line:



      try

        ActualNo := aqFileSystem.GetFolderInfo('c:\1').Files.Count;

      except

        ActualNo := 0;

      end;

  • Thanks for the feed-back. I will check if the proposed solution solves my problem.



    Herman
  • m_essaid's avatar
    m_essaid
    Valued Contributor

    Hi,

    This problem has not been solved... Still need to put a try/except to avoid the error.

    Mehdi

    • TanyaYatskovska's avatar
      TanyaYatskovska
      Icon for Alumni rankAlumni

      Hi Mehdi,

       

      Sad to hear this. Are you using the latest TestComplete version – v. 10.60? If you are, could you please report the issue to our Customer Care team ( http://support.smartbear.com/product-list/ )?

       

      Update: 

      Our R&D team has decided to stay this for the backward compatibility. Thus, try…catch should be used to avoid the error.

       

      • m_essaid's avatar
        m_essaid
        Valued Contributor

        Hi Tanya,

         

        Ok, thanks for the feedback.

         

        Have a nice day,

         

        Mehdi