Micro Focus QTP (UFT) Forums
Need to compare files from two diff folders - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Need to compare files from two diff folders (/Thread-Need-to-compare-files-from-two-diff-folders)



Need to compare files from two diff folders - maktha1 - 11-05-2011

Hey Friends ... please can you help me on this ..

scenario: I got two folders one is old version folder and other is new version folder.. There are about 100 files in that folder.. so i need to compare each one filein old version folder with other file in new version folder ,I have written below code .. it is working if i mention path for each file..but I need to put in loop so that it checks all files in the folders...

Code:
Option explicit
Dim File_Sys_Obj, File_Obj1, File_Obj2, Old_V_Folder, New_V_Folder, OVFiles, NVFiles, OFile, NFile, Str2, Str1 ,File ,Name_File,fldext                                    
Set File_Sys_Obj = createobject("Scripting.FileSystemObject")                                          
Set Old_V_Folder =  File_Sys_Obj.GetFolder("U:\Similar")  
Set  New_V_Folder = File_Sys_Obj.GetFolder("U:\Different")  
Set OVFiles =Old_V_Folder.Files
Set  NVFiles = New_V_Folder.Files
NFile ="U:\Different\first.txt"
OFile ="U:\Similar\first.txt"
For  each File  in OVFiles
'z = File.name
Name_File = File.path
Set File_Obj1 = File_Sys_Obj.OpenTextFile(Name_File,1,false)
Set File_Obj2 = File_Sys_Obj.OpenTextFile(NFile,1,false)
While  File_Obj1.AtEndOfStream <> true
Str1= File_Obj1.ReadAll
Str2= File_Obj2.ReadAll
If  StrComp(Str1, Str2, 0)   <> 0 Then
Msgbox "Files not Identical"
If File_Sys_Obj.FolderExists("U:\HeyNotSim")then
File_Sys_Obj.CopyFile "U:\Similar\first.txt","U:\HeyNotSimi/first.txt",True
Else    
File_Sys_Obj.CreateFolder("U:\HeyNotSimi")
File_Sys_Obj.CopyFile "U:\Similar\first.txt","U:\HeyNotSimi\",True
End If
reporter.ReportEvent micFail, " Two Files Are Not  Similar","Failure"
Else
Msgbox "Files Identical"
'fso.CopyFile "C:\Users\sarishr\Desktop\first.txt","C:\Users\sarishr\Desktop\Similar\first.txt",True
Reporter.ReportEvent micPass, "Two Files Are Similar"," Sucess"
End If
Wend
Next
Set File_Obj1 = Nothing
Set File_Obj2 = Nothing
Set OVFiles = Nothing
Set NVFiles = Nothing
Set Old_V_Folder=Nothing
Set  New_V_Folder = Nothing
Set   File_Sys_Obj = Nothing