Ask a Question

Files.Compare returns exception

Frequent Contributor

Files.Compare returns exception


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');



.Compare("C:\\myfiles\\Bun26.PDF",'C:\\Bun26' + r2wdate + 'T000000.PDF');Thanks.Sumedha
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.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Frequent Contributor

Thanks Robert .I was using it without adding the "files" object in the Stores. It is working fine now.


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 ?


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();


// Reads the second text file

file2 = fso.OpenTextFile(fileName2, ForReading);

fileText2 = file2.ReadAll();


// 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");



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




Hi Sumedha,

Please send us the target PDF files. We'll try to create a sample script for you.
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Showing results for 
Search instead for 
Did you mean: