Forum Discussion

mikev's avatar
mikev
Contributor
13 years ago

File, Directories and Comparisons

New to TC, migrating from QTP.  We have the following functions that we used quite heavily in QTP:



CompareFiles - Compares two files for differences.  Doesn't matter if the file is binary or not.  If the file is ASCII, and there is a mismatch, and difference file (HTML report)  is generated.  If it's Binary, we just want to know that it was different.



FileIsBinary - Returns True or False.  Used in CompareFiles above.



CompareDirectoryContents - Compares the contents (not the files) of a directory.  File names, directories, etc.



CompareDirectoryFiles - Compares all files in a single directory.



CompareDirectoryFilesRecursive - Compares all files in all directories, given the parent.



In the research that I've done so far, TC makes it pretty easy (I think) to do these kinds of things as long as the file(s) themselves are in the Store.  I can't do that, as some of the directories that I need to compare have over 10,000 (not a typo) files in them.  In addition, one of the things that I do in the above functions is to check the hashmap.  I didn't/don't see how to do that in TC.  Actually, we used MD5 for that, but I don't think I can create a TC CreateObject, as it's only for an OCR Object.  I already have some 3rd party applications to actually compare the files and create a nice difference file, and I'll certainly make use of them.



I'm more than willing to take on these functions (and certainly post them here for others to use) as I get them done, but I'm curious to see if others have already dones something similar (and are willing to share), and if there's a way that I can do the same kinds of things that are already provided by TC.  I'm aware of the aqFiles object.



Anyone have any pointers or code to share?

4 Replies

  • If anyone has any ideas on how to find the hash map value of a file, and a way to check to see if a file is binary, WITHOUT using STORE|Files that would be really great.
  • Have you looked into using the aqFile and aqFileSystem objects?




    Yes.  As far as I can tell, in order to use those, the files must also be part of the project.  In other words, they are in the STORES | Files, and I can't have that.  I'm getting close on the hashmap problem that I mentioned, I'm just trying to figure out the JScript equivalent of VBScript CreateObject.  I have an MD5.dll that I was using in QTP, and I'm trying to implement that now.  I don't know why I'm trying to convert the QTP VBS scripts to TC JScript (glutton for punishment?) but I am.  I suppose it's basically the try/catch that's luring me there.



    Once I figure this out, I'll make a new thread about the hashmap, and I'll include all of my code (and the .vbs script to register the .dll) there.  Since we have so many files to compare, using the hashmap value is far more efficient and faster.  That's why I'm using that.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Actually, no.  aqFile and aqFileSystem have nothing to do with the Files object in stores.



    Check it out here:



    http://support.smartbear.com/viewarticle/12057/

    http://support.smartbear.com/viewarticle/13235/



    And for that matter, the Files.CalculateHashValue method can be used with regular files as well as files in the stores.  Check it out 



    http://support.smartbear.com/viewarticle/11069/



    Quote from there:


    The method has the following parameters:




    File1 and File2




    Specify the files whose hash value you want to calculate. You can either use the file name (including the path), or, if the file belongs to the Stores | Files collection, specify the file name in this collection.





    Files.Compare has the same concept... either the files being compared are in Stores, or you pass in the full file path to the file for use in comparison.