Hi, we use Powershell's Compare-Object method to compare CSV and XML files. We pass the function the full paths of the files to compare. The function returns True or False depending on the comparison result. Additionally, if the comparison fails it outputs a file showing only the differences. Below is the VBScript function.
Function AtsCompareFilesPS(RFile, TFile)
Dim oShell, oExec, strOutput
Dim o_Tfile
s_gpDirectory = Project.Variables.s_gpDirectory
Set oShell = Sys.OleObject("WScript.Shell")
'-- Get the full path of the test file w/out the extension
i_FNameLen = Len(TFile)
s_FNameNoExt = Left(TFile, i_FNameLen-4) 'Strip the extension
'-- Compare the files using Powershell
s_PowershellInput = "powershell -command Compare-Object -ReferenceObject $(Get-Content '" & RFile & "') -DifferenceObject $(Get-Content '" & TFile & "') | where {$_.SideIndicator -eq '<=' -and !$_.InputObject.StartsWith('#')} | select -ExpandProperty inputObject"
Set oExec = oShell.Exec(s_PowershellInput)
oExec.StdIn.Close ' Close standard input before reading output
' Get PowerShell output with the comparison results
strOutput = oExec.StdOut.ReadAll
'-- If strOutput is "" then the files matched
If strOutput = "" Then
AtsCompareFilesPS = True
Else 'Return false and save the output to a text file in the same location as the test file
AtsCompareFilesPS = False
s_LogFullPath = s_FNameNoExt & "-PS-Diifs"& ".txt"
'Delete an existing log with the same name if it exists
If aqFile.Exists(s_LogFullPath) Then aqFile.Delete(s_LogFullPath)
'Create the new log
If (aqFile.Create(s_LogFullPath) = 0) Then
' If the file has been created successfully, write the comparison results to it
Call aqFile.WriteToTextFile(s_LogFullPath, strOutput, aqFile.ctUTF8)
Call Log.Message("A log file was written with the failed comparison results.")
Else
Call Log.Warning("The comparison log could not be created.")
End If
End If
End Function