msmou Posted June 27, 2012 Share Posted June 27, 2012 Two files are present.I want to compare the two files text by text(line by line) and verify if they are same and also compare their file size.Can anyone please suggest. Thanks Link to comment Share on other sites More sharing options...
water Posted June 27, 2012 Share Posted June 27, 2012 Does it have to be AutoIt or will another tool like Winmerge fit your needs too? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
msmou Posted June 27, 2012 Author Share Posted June 27, 2012 I have to do through Autoit Automation and then pass the result as success or fail Link to comment Share on other sites More sharing options...
water Posted June 27, 2012 Share Posted June 27, 2012 Use function "FileGetSize" to retrieve the size of a file.How big are the files you need to compare? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
msmou Posted June 27, 2012 Author Share Posted June 27, 2012 20 kb file size . FileGetSize will compare the file size. But how to compare the file contents. ex:I have a file ex: data.txt in PC location.I downloaded the same file data.txt from cloud.so i need to compare the file contents.If both file contents and size are same then pass msg as file downloaded successfully. Link to comment Share on other sites More sharing options...
water Posted June 27, 2012 Share Posted June 27, 2012 (edited) Something like this? Pass the two filenames to compare to the function. ; Compare FileSize and Content. Returns 1 if equal, 0 if not equal, -1 for error Func _CompareFiles($sFile1, $sFile2) If FileGetSize($sFile1) <> FileGetSize($sFile2) Then Return 0 $sFile1Content = FileRead($sFile1) If @error Then Return -1 $sFile2Content = FileRead($sFile2) If @error Then Return -1 If $sFile1Content <> $sFile2Content Then Return 0 Return 1 EndFunc ;==>_CompareFiles Edited June 27, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
UEZ Posted June 27, 2012 Share Posted June 27, 2012 Here another way to compare line by line: expandcollapse popup#include <Array.au3> #include <File.au3> $aFileCompare = TextFileCompare("C:TempSilverlight0.log", "C:TempSilverlight1.log") _ArrayDisplay($aFileCompare) Func TextFileCompare($sFile1, $sFile2) If Not FileExists($sFile1) Or Not FileExists($sFile2) Then Return SetError(1, 0, 0) ;at least one file doesn't exist If Not FileGetSize($sFile1) Or Not FileGetSize($sFile1) Then Return SetError(2, 0, 0) ;at least one file is empty Local $aFile1, $aFile2, $i, $j = 1 _FileReadToArray($sFile1, $aFile1) If @error Then Return SetError(3, @error, 0) ;file couldn't be read to the array _FileReadToArray($sFile2, $aFile2) If @error Then Return SetError(4, @error, 0) ;file couldn't be read to the array Local $aResult[Max($aFile1[0], $aFile2[0]) +2][3] Local $iMin = Min($aFile1[0], $aFile2[0]) Local $bDiff = False For $i = 1 To $iMin If $aFile1[$i] <> $aFile2[$i] Then ConsoleWrite("Line " & $i & ": " & $aFile1[$i] & " <!> " & $aFile2[$i] & @LF) $aResult[$j][0] = $i $aResult[$j][1] = $aFile1[$i] $aResult[$j][2] = $aFile2[$i] $bDiff = True $j += 1 EndIf Next If $aFile1[0] > $aFile2[0] Then $bDiff = True For $i = $aFile2[0] + 1 To $aFile1[0] ConsoleWrite("Line " & $i & ": " & $aFile1[$i] & " <!> " & @LF) $aResult[$j][0] = $i $aResult[$j][1] = $aFile1[$i] $aResult[$j][2] = "" $j += 1 Next ElseIf $aFile1[0] < $aFile2[0] Then $bDiff = True For $i = $aFile1[0] + 1 To $aFile2[0] ConsoleWrite("Line " & $i & ": " & " <!> " & $aFile2[$i] & @LF) $aResult[$j][0] = $i $aResult[$j][1] = "" $aResult[$j][2] = $aFile2[$i] $j += 1 Next EndIf If Not $bDiff Then ConsoleWrite("Files are equal!" & @LF) Return 0 EndIf $aResult[0][0] = "Line" $aResult[0][1] = $sFile1 $aResult[0][2] = $sFile2 ReDim $aResult[$j][3] Return $aResult EndFunc Func Min($a, $b) If $a < $b Then Return $a Return $b EndFunc Func Max($a, $b) If $a > $b Then Return $a Return $b EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now