Forum Discussion

sarya's avatar
sarya
Frequent Contributor
15 years ago

Files.Compare returns exception

Hi,



I am trying to comapre two pdf documents. I used this in my script  but when I run this code,it gives me an exception as " 'Files' is undefined" .Is this not the correct way to comapre files?




Files.Compare("C:\\myfiles\\Bun26.PDF",'C:\\Bun26' + r2wdate + 'T000000.PDF');



Thanks.

Sumedha


.Compare("C:\\myfiles\\Bun26.PDF",'C:\\Bun26' + r2wdate + 'T000000.PDF');Thanks.Sumedha
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    That is the correct syntax, assuming, though, that you a) the Stores object added to your project and that b) you have the Files object added to the Stores.  See the screenshot attached.
  • sarya's avatar
    sarya
    Frequent Contributor
    Thanks Robert .I was using it without adding the "files" object in the Stores. It is working fine now.



    Thanks,

    sumedha
  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Robert,



    I have one more doubt. I compared two files ,both look to be same but somehow the file comparison from test complete gives me error  with some hash value.



    The files "C:\tcfiles\bundler\Bun29.PDF" and "C:\Bun292010-04-15T000000.PDF" are not equal. HashValue = 36820037. 



    So can we not come to know particularly where the comparison failed in whole report ?



    Thanks,

    Sumedha
  • sarya's avatar
    sarya
    Frequent Contributor
    I also used the code to ignore the date timestamps but still it fails. If the date timestamp is same,the comparison passes but even after using this code,it fails.


    function CompareFiles(fileName1, fileName2)


    CompareFiles(fileName1, fileName2)

    {


    var fso, file1, file2, regEx;


    var fileText1, fileText2, newText1, newText2;


    var ForReading = 1;


    // Creates the FileSystemObject object


    fso = new ActiveXObject("Scripting.FileSystemObject");


    // Reads the first text file


    file1 = fso.OpenTextFile(fileName1, ForReading);


    fileText1 = file1.ReadAll();


    file1.Close();


    // Reads the second text file


    file2 = fso.OpenTextFile(fileName2, ForReading);


    fileText2 = file2.ReadAll();


    file2.Close();


    // Specifies the regular expression pattern for the date/time mask


     The date is in this format  4/15/2010 2:09 PM


    regEx = /\d{1,2}.\d{1,2}.\d{2,4}\s\d{1,2}:\d{1,2}\s\w{2}/gim;


    // Replaces the text matching the specified date/time format with <ignore>


    newText1 = fileText1.replace(regEx, "<ignore>");


    newText2 = fileText2.replace(regEx, "<ignore>");


    // Compares the text


    return (newText1 == newText2);


    }




    function Main()



    {


    var fileName1 = 'C:\\Bun211' + r2wdate + 'T000000.PDF';


    var fileName2 = "C:\\Users\\sarya\\Documents\\TestComplete 7 Projects\\ClientRegression\\Bundler\\Stores\\Files\\Bun211.PDF";


    if (CompareFiles(fileName1, fileName2))


    Log.Message("The files are equal");


    else

     



    Log.Error("The files are different");


    }



    Thanks,

    Sumedha