Jump to content

Compare file text and size


Recommended Posts

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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 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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here another way to compare line by line:

#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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...