Search the Community
Showing results for tags 'Compare'.
-
I read various threads and theories regarding two string matching and convert matching value into Percentage. there are some algorithms to calculate similarity like Lowenstein, but sometimes you need more then that So, I written this code, and you will use it at your convenience script matches two strings with word by word OR character by character also match by case OR non case format you can also find difference with (100 – Result) If any suggestion then please write here #include <Array.au3> #include <File.au3> #include <Math.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> $sStr01 = "My string Software v1.0" $sStr02 = "My String Software v1.1" ConsoleWrite("Standard: " & _StringMatchPercent($sStr01, $sStr02) & @CRLF) ; Return Standard: 95.65 ConsoleWrite("Case ON (Char lvl): " & _StringMatchPercent($sStr01, $sStr02, 1, 0) & @CRLF) ; Return "Case ON (Char lvl): 91.3" ConsoleWrite("Case ON (word lvl): " & _StringMatchPercent($sStr01, $sStr02, 1, 1) & @CRLF) ; Return "Case ON (word lvl): 50" ConsoleWrite("Case Off (Char lvl): " & _StringMatchPercent($sStr01, $sStr02, 0, 0) & @CRLF) ; Return "Case Off (Char lvl): 95.65" ConsoleWrite("Case Off (word lvl): " & _StringMatchPercent($sStr01, $sStr02, 0, 1) & @CRLF) ; Return "Case Off (word lvl): 75" Func _StringMatchPercent($FirstString = "", $SecondString = "", $iCaseSense = 0, $iMatchByWord = 0) ;~ ($iCaseSense : [0 = not case sensitive [, 1 = case sensitive]]) ;~ $iSplitByWord : [0 = Match Character by Character [, 1 = Match word by Word]] ;~ ### Check/Set function header parameters Local $sMatchBy = ($iMatchByWord = 0) ? "" : " " Local $inCaseSense = ($iCaseSense = 0) ? 0 : 1 If $FirstString = "" Or $SecondString = "" Then Return "0" Local $aFirstArray = StringSplit($FirstString, $sMatchBy, 2) _ArraySort($aFirstArray) ; Sort Array to Ascending Order ;~ _ArrayDisplay($aFirstArray,"Show First Array") Local $aSecondArray = StringSplit($SecondString, $sMatchBy, 2) _ArraySort($aSecondArray) ; Sort Array to Ascending Order ;~ _ArrayDisplay($aSecondArray,"Show Second Array") Local $inSL = 0 ;Second Level matching starting Point Local $iMatchCount = 0 Local $sMatchArg = 0 ; Now Matching Every First Array Element to Second Array Element For $iFL = 0 To UBound($aFirstArray) - 1 ; $iPL = Represent First Array Position For $iSL = $inSL To UBound($aSecondArray) - 1 ; $iSL = Second Array Position $inSL = Second Array Checking Start from If StringCompare($aFirstArray[$iFL], $aSecondArray[$iSL], $inCaseSense) = 0 Then ; If Both Element Matched $iMatchCount += 1 ; Match Count get +1 $inSL = $iSL + 1 ; Set New Starting Position for Second Array ExitLoop ; Exit Loop for checking next element EndIf Next Next Local $iMax = _Max(UBound($aFirstArray), UBound($aSecondArray)) ; Finding Large Array for Calculation Return Round((($iMatchCount <> 0) ? (($iMatchCount / $iMax) * 100) : 0), 2) EndFunc
-
As discussed here: I created a DLL (x86 and x64) to do a file compare like the FC.exe does (only binary comparison!) but filling up the memory which can be read out by Autoit. UDF _WinAPI_FileCompare.au3: ;Version v0.70 build 2024-03-23 beta #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_FileCompareBinaryString ; Description ...: Reads two files into the memory and compares them byte by byte. Result is saved in the memory. ; Syntax ........: _WinAPI_FileCompareBinaryString($sFile1, $sFile2, Byref $tMemArray) ; Parameters ....: $sFile1 - first file to read. ; $sFile2 - second file to read. ; $tMemArray - a ptr dll struct which holds a ptr entry which is filled by the DLL. ; Return values .: Number of unequal bytes found in both files otherwise negative value on error. ; Author ........: UEZ ; Modified ......: ; Remarks .......: The memory pointer $tMemArray must be released using _MemGlobalFree() which holds the pointer to the result. ; The result contains hex string values (offset, file1, file2) from the differences between the two files. ; Large memory consumption for files > 80 MB as everything is kept in memory! ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/index.php?showtopic=211619 ; Example .......: No ; =============================================================================================================================== Func _WinAPI_FileCompareBinaryString($sFile1, $sFile2, ByRef $tMemArray) If Not FileExists($sFile1) Then Return SetError(-10, 0, 0) If Not FileExists($sFile2) Then Return SetError(-20, 0, 0) If Not FileGetSize($sFile1) Then Return SetError(-30, 0, 0) If Not FileGetSize($sFile2) Then Return SetError(-40, 0, 0) If Not IsDllStruct($tMemArray) Then Return SetError(-50, 0, 0) Local $aReturn = DllCall(@AutoItX64 ? "_WinAPI_FileCompare_x64.dll" : "_WinAPI_FileCompare.dll", "int64", "_WinAPI_FileCompareBinaryString", "str", $sFile1, "str", $sFile2, "struct*", $tMemArray) If @error Then Return SetError(-60, 0, 0) If $aReturn[0] < 0 Then SetError($aReturn[0], 0, 0) Return $aReturn[0] EndFunc ;==>_WinAPI_FileCompareBinaryString ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_FileCompareBinary ; Description ...: Reads two files into the memory and compares them byte by byte. Result is saved in the memory. ; Syntax ........: _WinAPI_FileCompareBinary($sFile1, $sFile2, Byref $tMemArray) ; Parameters ....: $sFile1 - first file to read. ; $sFile2 - second file to read. ; $tMemArray - a ptr dll struct which holds a ptr entry which is filled by the DLL. ; Return values .: Number of unequal bytes found in both files otherwise negative value on error. ; Author ........: UEZ ; Modified ......: ; Remarks .......: The memory pointer $tMemArray must be released using _MemGlobalFree() which holds the pointer to the result. ; The result contains integer values (offset, file1, file2) from the differences between the two files. ; Large memory consumption as everything is kept in memory but 1/3 less than _WinAPI_FileCompareBinaryString. ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/index.php?showtopic=211619 ; Example .......: No ; =============================================================================================================================== Func _WinAPI_FileCompareBinary($sFile1, $sFile2, ByRef $tMemArray) If Not FileExists($sFile1) Then Return SetError(-10, 0, 0) If Not FileExists($sFile2) Then Return SetError(-20, 0, 0) If Not FileGetSize($sFile1) Then Return SetError(-30, 0, 0) If Not FileGetSize($sFile2) Then Return SetError(-40, 0, 0) If Not IsDllStruct($tMemArray) Then Return SetError(-50, 0, 0) Local $aReturn = DllCall(@AutoItX64 ? "_WinAPI_FileCompare_x64.dll" : "_WinAPI_FileCompare.dll", "int64", "_WinAPI_FileCompareBinary", "str", $sFile1, "str", $sFile2, "struct*", $tMemArray) If @error Then Return SetError(-60, 0, 0) If $aReturn[0] < 0 Then SetError($aReturn[0], 0, 0) Return $aReturn[0] EndFunc ;==>_WinAPI_FileCompareBinary ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_FileComparePrint ; Description ...: Reads two files into the memory and compares them byte by byte. Result will be printed to the console only. ; Syntax ........: _WinAPI_FileComparePrint($sFile1, $sFile2[, $bUnbuffered = False]) ; Parameters ....: $sFile1 - first file to read. ; $sFile2 - second file to read. ; $bUnbuffered - [optional] a boolean value. Default is False. If $bUnbuffered then file will be read ; byte by byte and result will be displayed, otherwise both files will be read into the ; memory and then compared. ; Return values .: 1 if successfull, otherwise 0. ; Author ........: UEZ ; Modified ......: ; Remarks .......: Use #AutoIt3Wrapper_Change2CUI=y when compiling to display result in console. ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/index.php?showtopic=211619 ; Example .......: No ; =============================================================================================================================== Func _WinAPI_FileComparePrint($sFile1, $sFile2, $bUnbuffered = False) If Not FileExists($sFile1) Then Return SetError(-10, 0, 0) If Not FileExists($sFile2) Then Return SetError(-20, 0, 0) If Not FileGetSize($sFile1) Then Return SetError(-30, 0, 0) If Not FileGetSize($sFile2) Then Return SetError(-40, 0, 0) DllCall(@AutoItX64 ? "_WinAPI_FileCompare_x64.dll" : "_WinAPI_FileCompare.dll", "none", "_WinAPI_FileComparePrint", "str", $sFile1, "str", $sFile2, "bool", $bUnbuffered) If @error Then Return SetError(-60, 0, 0) Return 1 EndFunc ;==>_WinAPI_FileComparePrint Func _WinAPI_FileCompareAbout() DllCall(@AutoItX64 ? "_WinAPI_FileCompare_x64.dll" : "_WinAPI_FileCompare.dll", "none", "About") EndFunc ;==>_WinAPI_FileCompareAbout Example1: ;Coded by UEZ build 2024-03-22 beta #AutoIt3Wrapper_UseX64=y #include <WinAPIFiles.au3> #include <Memory.au3> #include "_WinAPI_FileCompare.au3" Global $tMemArray = DllStructCreate("ptr addr") Global $fTimer = TimerInit() Global $iReturn = _WinAPI_FileCompareBinaryString("img1.bmp", "img2.bmp", $tMemArray) ConsoleWrite("Dll runtime: " & TimerDiff($fTimer) & " ms" & @CRLF) If $iReturn Then If _WinAPI_IsBadReadPtr($tMemArray.addr, $iReturn) <> 1 Then ConsoleWrite(@CRLF) ConsoleWrite("Displaying result..." & @CRLF) ConsoleWrite("Offset" & @TAB & @TAB & "File1" & @TAB & "File2" & @CRLF) Global $i, $j, $t, $c = 0 For $i = 0 To $iReturn For $j = 0 To 2 $t = DllStructCreate("char string[15]", Ptr($tMemArray.addr + $i * 15 + ($j = 0 ? $j : 6 + $j * 3))) ConsoleWrite($t.string & ($j = 0 ? ":" : "") & @TAB) Next $c += 1 ConsoleWrite(@CRLF) Next ConsoleWrite(@CRLF) ConsoleWrite("Found " & $c & " differences!" & @CRLF) ConsoleWrite(@CRLF) If $tMemArray.addr Then _MemGlobalFree($tMemArray.addr) Else ConsoleWrite("Access violation to memory address" & @CRLF) EndIf Else ConsoleWrite("Files are equal!" & @CRLF) EndIf Example2: ;Coded by UEZ build 2024-03-22 beta #AutoIt3Wrapper_UseX64=y #include <WinAPIFiles.au3> #include <Memory.au3> #include "_WinAPI_FileCompare.au3" Global $tMemArray = DllStructCreate("ptr addr") Global $fTimer = TimerInit() Global $iReturn = _WinAPI_FileCompareBinary("img1.bmp", "img2.bmp", $tMemArray) ConsoleWrite("Dll runtime: " & TimerDiff($fTimer) & " ms" & @CRLF) If $iReturn Then If _WinAPI_IsBadReadPtr($tMemArray.addr, $iReturn) <> 1 Then ConsoleWrite(@CRLF) ConsoleWrite("Displaying result..." & @CRLF) ConsoleWrite("Offset" & @TAB & @TAB & "File1" & @TAB & "File2" & @CRLF) Global $i, $j, $t, $c = 0 For $i = 0 To $iReturn For $j = 0 To 2 Switch $j Case 0 $t = DllStructCreate("ulong offset", Ptr($tMemArray.addr + $i * 8)) ConsoleWrite(Hex($t.offset, 8) & ":" & @TAB) Case 1 $t = DllStructCreate("ubyte hex1", Ptr($tMemArray.addr + $i * 8 + 4)) ConsoleWrite(Hex($t.hex1, 2) & @TAB) Case 2 $t = DllStructCreate("ubyte hex2", Ptr($tMemArray.addr + $i * 8 + 5)) ConsoleWrite(Hex($t.hex2, 2) & @TAB) EndSwitch Next $c += 1 ConsoleWrite(@CRLF) Next ConsoleWrite(@CRLF) ConsoleWrite("Found " & $c & " differences!" & @CRLF) ConsoleWrite(@CRLF) If $tMemArray.addr Then _MemGlobalFree($tMemArray.addr) Else ConsoleWrite("Access violation to memory address" & @CRLF) EndIf Else ConsoleWrite("Files are equal!" & @CRLF) EndIf Example3: ;Coded by UEZ build 2024-03-22 beta #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #include "_WinAPI_FileCompare.au3" _WinAPI_FileComparePrint("img1.bmp", "img2.bmp") I used the two images from here: Examples output should look like this here (always hex values): Dll runtime: 5.6315 ms Displaying result... Offset File1 File2 0009AB99: F0 C7 0009AB9A: EF CB 0009AB9B: 81 34 0009C795: 23 00 0009C796: 7C 80 0009C797: F5 FF Found 6 differences! You can read out the result and put it to an array... With this version you should be able to use multi-threading / multi-calls of the DLL as the memory is now allocated with each call. For x86 it may fail when the memory cannot be allocated (2GB limit) and the dll will return 0. I may add another feature to the DLL to get around the x86 limitation at the expense of speed by using chunked memory allocation if it makes sense... All files can be found also in the 7-Zip archive. _WinAPI_FileCompare DLL v0.70 build 2024-03-22.7z
-
Scope of this script is to compare the users membership of two or more AD Groups, to understand complex active directory environments, and find groups/users overlapping. So you can retrieve the list of groups, select 2 or more groups and obtain a list with the membership of every user. The list is processed in sqlite and exported as a CSV file. Thank always to @water for the mighty active directory UDF. You will need also my _gollog UDF for logging. CompareADGroups.au3
-
- active directory
- active directory udf
-
(and 3 more)
Tagged with:
-
A few days ago I wrote a script to get the relative difference between two sets of data. When this comes to images we can detect all sorts of things, more accurately. Take for example you have two images with different lighting. http://prodynamics.co/link.php?CMD=file&ID=compare1 (1600x976) http://prodynamics.co/link.php?CMD=file&ID=compare2 (1600x976) (These are both jpg images, their format is stored in the database) You will notice that the second image is considerably brighter than the first. Every pixel of the second image is at least one shade brighter than the second, this means that there was an absolute change of 100% to the image, HOWEVER, lets say we only want to know how much light was added to the image, that's one of the things this script can detect. The script would say the image has only changed by 12%, that's because the new data is only 12% different than the old data, even though 100% of it has changed. Now in order to be efficient, the script which converts the images into pixel data are set to skip by default ever 2nd row of pixels and read every other pixel in each row. This still provides pretty accurate results for changes larger than 1px(1px changes may be missed sometimes), and could still accurately display where a change occurred or track a moving object.(with modification to use processed data in said way) In the case you are comparing images which have many 1px changes, you can set the step for both y and x to 1, and the function will compare every single pixel. Be warned though, this is very slow. Large images can use a higher step, but using too high of a step may exclude certain changes from being observed. That being said, if you want to compare large images quickly, without leaving out too much data, there is an alternative, you can size the image down to 1/4th 1/6th or 1/8th it's size and compare it. Scaling down two images keeps the relative data in them the same places, so the comparison will return almost identical results (off by maybe 2% max)Note: In most cases scaling will result in more accurate results than stepping. The below example compares the above two images, and output the data to the console. ;~ #include <_PixelGetColor.au3> #include <GDIPlus.au3> #include <inet.au3> #include <array.au3> $hDll = DllOpen("gdi32.dll") _GDIPlus_Startup() Global $image1, $image2 $f1 = binary(_INetGetSource("http://prodynamics.co/link.php?CMD=file&ID=compare1")) ;image 1 $f2 = binary(_INetGetSource("http://prodynamics.co/link.php?CMD=file&ID=compare2")) ;image 2 brighter ;here we use the default step options $t1 = TimerInit() $image1 = _Capturepixels($f1) ;get image 1 pixel ConsoleWrite(TimerDiff($t1)/1000 &' Default Step'&@CRLF) $t1 = TimerInit() $image2 = _CapturePixels($f2) ;get image 2 pixels ConsoleWrite(TimerDiff($t1)/1000& ' Default Step'&@CRLF) $timer = TimerInit() $compare = _datacompare($image1[0], $image2[0]);compare them ConsoleWrite($compare[0]&'% Different(Localized) '&$compare[1]&'% Different(Global)'&@CRLF&'Took '&(TimerDiff($timer)/1000)&' seconds. Default Step'&@CRLF) ;here we double them, notice the preformance increase $t1 = TimerInit() $image1 = _Capturepixels($f1, 4, 8) ;get image 1 pixels ConsoleWrite(TimerDiff($t1)/1000 &' Double Step'&@CRLF) $t1 = TimerInit() $image2 = _CapturePixels($f2,4 , 8) ;get image 2 pixels ConsoleWrite(TimerDiff($t1)/1000& ' Double Step'&@CRLF) $timer = TimerInit() $compare = _datacompare($image1[0], $image2[0]) ConsoleWrite($compare[0]&'% Different(Localized) '&$compare[1]&'% Different(Global)'&@CRLF&'Took '&(TimerDiff($timer)/1000)&' seconds. Default Step'&@CRLF) sleep(5000) ;~ $t1 = TimerInit() ;~ $diffarray = _mapchange($image1[0], $image2[0], $image1[1], $image1[2]) ;compare two images for difference ;~ ConsoleWrite(TimerDiff($t1)/1000& ' _mapchange'&@CRLF) ;~ $t1 = TimerInit() ;~ $image = _toimage($diffarray) ;here we turn the array of colors back into an image ;~ ConsoleWrite(TimerDiff($t1)/1000& ' _toimage'&@CRLF) ;~ _GDIPlus_ImageSaveToFile($image, @scriptdir&'\test.jpg') ;write it to a file ;~ shellexecute(@scriptdir&'\test.jpg') #cs Function _datacompare($data1, $data2, [$declimal]) -$data1: A string of data, any length. -$data2: A string of data, must be the same length as $data1 -$decimal: 1=Binary 9=Base-10, 15=Base-16, 31=Base-32 Note: If you just want to compare two sets of binary data you probably want to use base-16. Unless you are sure your binary is in 1's and 0's. Returns: An array containing two floats. The first value is the localized change, and the second is the global change #ce func _datacompare($data1, $data2, $decimal=15) Local $difference $data1 = StringSplit($data1, "") $data2 = StringSplit($data2, "") $difference = 0 $found = 0 for $i=1 to $data1[0] if $data1[$i] <> $data2[$i] Then $temp = Abs(_tonum($data1[$i]) - _tonum($data2[$i])) $difference += $temp $found +=1 EndIf Next dim $ret[2] $ret[0] = ((($difference/$found))/$decimal)*100 $ret[1] = ((($difference/$data1[0]))/$decimal)*100 Return $ret EndFunc #cs Function: _mapchange($base, $new, $x, $y, [$decimal]) $base: Base data to compare from $new: Data to compare $x: Width of output data (should be returned by capturepixels) $y: Height of outout data (should be returned by capturepixels) $decimal: Decimal system, you shouldn't change this Note: Use _toimage on data returned by this function to visually see a image of the change. (The lighter the color the more change the occured) Returns an 2D array of data. Each value of the array represents one pixel of the image. Each value is a percent between 0-100 representing the change that occured in that pixel #ce func _mapchange($base, $new, $y, $x, $decimal = 10) Local $difference, $xx = 0, $yy = 0 dim $result[1][$x+1] $t1 = TimerInit() $data1 = _StringequalSplit($base, 8) $data2 = _StringequalSplit($new, 8) $difference = 0 for $i=1 to UBound($data1)-1 if $xx > $x Then $xx=0 $yy+=1 ConsoleWrite($yy&'/'&$y&' ('&($yy/$y)*100&') '&@CRLF) redim $result[$yy+1][$x+1] EndIf if $data1[$i] <> $data2[$i] Then $values1 = StringSplit($data1[$i], "") $values2 = stringSplit($data2[$i], "") $diff = "" for $ix=1 to $values1[0] $diff += round((Abs(_tonum($values1[$ix]) - _tonum($values2[$ix]))/$decimal)*100) Next $diff = Round($diff/$values1[0]) $result[$yy][$xx] = $diff Else $result[$yy][$xx] = 0 EndIf $xx += 1 Next return $result EndFunc #cs Function _tonum($info) -$info: A single digit or carachter. Returns: A 0-based value. #ce func _tonum($info) if $info+0 > 0 Then Return $info $info = StringLower($info) $return = asc($info)-87 switch $return Case -39 Return 0 Case Else Return $return EndSwitch EndFunc #cs Function _CapturePixels($data, [[$stepy], $stepx]) -$data: Binary Data -$stepy: How often to skip a row of pixelxs. 1 = Never -$stepx: How often to skip a single pixel. 1 = Nevere Note: Use higher steps for larger images and lower steps for smaller images. #ce Func _CapturePixels($data, $stepy = 2, $stepx = 2) $ret = "" $HBITMAP2 = _GDIPlus_BitmapCreateFromMemory($data) $y=_GDIPlus_ImageGetWidth($HBITMAP2) $x=_GDIPlus_ImageGetHeight($HBITMAP2) For $iY = 0 To $x step $stepy For $iX = 0 To $y step $stepx $rety = StringRight(hex(_GDIPlus_BitmapGetPixel($hBitmap2, $ix, $iy)),8) ;get current pixel color $ret &= $rety ;~ ConsoleWrite($iy&'/'&$x&' '&$rety&@CRLF) Next Next ;For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP2) ; For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP2) ; $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll) ; Next ;Next _WinAPI_DeleteObject($HBITMAP2) dim $retx[3] $retx[0] = $ret $retx[1] = $x/$stepx $retx[2] = $y/$stepy Return $retx EndFunc ;==>Capturepixels Func _toimage($colors) _GDIPlus_Startup() Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(UBound($colors, 2), UBound($colors, 1)) ;create an empty bitmap Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the graphics context of the bitmap _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hBmpCtxt, 0x00000000) ;clear bitmap with color white for $i=0 to UBound($colors)-1 for $i2=0 to UBound($colors,2 )-1 ;~ if $colors[$i][$i2] > 30 Then ;~ ConsoleWrite($i&","&$i2&' - '&$colors[$i][$i2]&@CRLF) _GDIPlus_BitmapSetPixel($hBitmap, $i2, $i, $colors[$i][$i2]&'0') ;~ ConsoleWrite($i2&','&$i&' '&$colors[$i][$i2]&@CRLF) ;~ EndIf Next Next return $hBitmap ;return bitmap ;cleanup GDI+ resources _GDIPlus_GraphicsDispose($hBmpCtxt) EndFunc ;==>Example Func _StringEqualSplit($sString, $iNumChars) If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0) If (Not IsInt($iNumChars)) Or $iNumChars < 1 Then Return SetError(2, 0, 0) Return StringRegExp($sString, "(?s).{1," & $iNumChars & "}", 3) EndFunc Cheers,NullSchritt PS: If I find the time, I'll add a motion tracking version of the script as well. (It can detect but not track motion in it's current form)
- 16 replies
-
I have this code It gets variable input from GUI to run a loop and write to a text file then copy it to the clipboard But the thing is code runs normally with $px and $py <100 or both > 100 or with $px <10 and $py>100 but It's wrong with 10<$px <100 and $py >100 Can anyone tell me why? Func clone() Local $px = GUICtrlRead($input1) Local $py = GUICtrlRead($input2) Local $temp = "C:\temp.csv" FileDelete($temp) While $px <= $py Local $name = "P"&$px FileWrite($temp, " & $name & ""& @CRLF) $px+= 1 WEnd $a=FileRead($temp) ClipPut($a) MsgBox($MB_ICONINFORMATION,"","Copied to Clipboard") EndFunc
-
Haven't had much time to code recently. However the following thread inspired me. The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method). I will delete that old code in due course. With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element. Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
-
We can get a list of file using the below code. Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.?? And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?
-
Generally we will use tools like Winmerge or Beyond Compare for this purpose. Are there any UDF or libraries available in AutoIT to compare any two files or folder contents.
-
Hello, I'm having trouble whit a scipt what I'm building where this is a snippit from, and hope somebody can help me whit. The problem lies in when i push the "add" button i want to check if the "user" already exists. But the search code i build founds 2 hits when i know there is only 1 hit. does somebody knows what I'm doing wrong? thanks in advance. Ps. if somebody knows " if i found the right user how can i rewrite the password for him/her? " an answer to that will be most appriciated #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <Array.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #Include <Timers.au3> #include <Crypt.au3> #include <GuiEdit.au3> $Form1 = GUICreate("Pie", 170, 235, 190, 200) local $usernames[0] local $passwords[0] global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20) $addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30) $usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20) $passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020) func encrypt() Local $hFileOpen = FileOpen("data.srmt", $FO_APPEND) if guictrlread($usernamefield) <> "" then ;~ local $encryptedusername = string(guictrlread($usernamefield)) ;~ local $encryptedpassword = string(guictrlread($passwordfield)) local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128)) local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128)) Local $iCheck_hit = False ConsoleWrite (@CRLF & "##############################################"& @CRLF) if ubound($usernames)> 0 then for $i = 0 to ubound($usernames)-1 If guictrlread($usernamefield) = $usernames[$i] Then $iCheck_hit = True ConsoleWrite ( "Found! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF) ;~ Else ;~ ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF) EndIf next EndIf ConsoleWrite ( "##############################################"& @CRLF) If $iCheck_hit = False Then FileWrite($hFileOpen, $encryptedusername & @CRLF) FileWrite($hFileOpen, $encryptedpassword & @CRLF) EndIf EndIf FileClose($hFileOpen) EndFunc func decrypt() Local $hFileOpen = FileOpen("data.srmt", $FO_READ) ;~ consolewrite(_FileCountLines("data.srmt") & " lines in the file" & @CRLF) for $i = 1 to _FileCountLines("data.srmt")/2 local $encryptedusername = FileReadLine($hFileOpen) local $encryptedpassword = FileReadLine($hFileOpen) ;~ consolewrite($encryptedusername & @CRLF) ;~ consolewrite($encryptedpassword & @CRLF) ;~ _ArrayAdd($usernames, FileReadLine($hFileOpen)) ;~ _ArrayAdd($passwords, FileReadLine($hFileOpen)) _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128))) _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128))) Next FileClose($hFileOpen) ;~ consolewrite(ubound($usernames) & " entries in array") ;~ _arraydisplay($usernames) if ubound($userNames)> 0 then for $i = 0 to ubound($usernames)-1 GUICtrlSetData($selectuser, $usernames[$i]) next EndIf endfunc func updatecomboandinfo() if not GUICtrlRead($usernamefield) = "" Then _ArrayAdd($usernames, GUICtrlRead($usernamefield)) _ArrayAdd($passwords, GUICtrlRead($passwordfield)) GUICtrlSetData($selectuser, $usernames[UBound($usernames)-1]) EndIf EndFunc decrypt() GUISetState(@SW_SHOW) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $addusername updatecomboandinfo() encrypt() GUICtrlSetData($usernamefield, "") GUICtrlSetData($passwordfield, "") Case $selectuser if ubound($usernames)> 0 then for $i = 0 to ubound($usernames)-1 ;~ msg( "error",$array_decrypted_usernames[$i]) If $usernames[$i] = GUICtrlRead($selectuser) Then GUICtrlSetData($usernamefield, $usernames[$i]) GUICtrlSetData($passwordfield, $passwords[$i]) consolewrite("YES " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF) Else ;~ msg( "error",$array_decrypted_usernames[$i]) consolewrite("NO " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF) EndIf next EndIf EndSwitch WEnd
-
hi I'm trying to make a script that runs different functions depending on the local time of the computer I tried to do if _NowCalcDate < 2016/04/12 Then functionA() Else functionB() Endif and that doesn't seem to work. I am assuming that value returned from _NowCalcDate doesn't match with the date type I wrote What should I do? I'd appreciate for any help that's given.
-
Hi guys, I'm getting some issues with timing: it's taking ages What I have: 46 .csv files circa (number may vary) Each of those has 6100 rows What I have to do: Compare a certain column (number) and if it's higher than the current one, update it I'm obviously doing this with 2 For cycles, one into each other but it's really slow. It takes about 65/70 seconds every 1000 records. Is there something else I can try to speed up the process? This is the For part I have: For $i=1 To $ListOfCSVs[0] Local $tempArray= 0 _FileReadToArray($tmpFiles&'\'&$ListOfCSVs[$i],$tempArray) ;MsgBox(0,$i,$tmpFiles&'\'&$ListOfCSVs[$i],$tempArray) $d=0 For $d=1 To $CompleteArray[0][0] ;SplashTextOn($i, "ID:"&$d, -1, -1, -1, -1, 4, "", 24) $searchSAM=_ArraySearch($tempArray, $CompleteArray[$d][0],2,0,0,1) If $searchSAM > 0 Then ;If found $searchSAM holds the position of the item just found $tmpItem=StringSplit($tempArray[$searchSAM],",") ;We're interested on the last row of $tmpItem >> $tmpItem[$tmpItem[0]] If $tmpItem[$tmpItem[0]] <> '' Then If $tmpItem[$tmpItem[0]] > $CompleteArray[$d][2] Then $CompleteArray[$d][2] = $tmpItem[$tmpItem[0]] EndIf EndIf EndIf ;Splashoff() Next Next I used the SplashTextOn to help me checking the speed of the cycle.. Cheers
-
Hey guys, saw a couple posts in the help section recently asking for a way to compare images, to get how different the two actually are. So I wrote a function that directly compares sets of data and gets how different one character is from the next. In other words this function won't tell you the percentage of data that changed what is does do is tell you is how different the two sets of data are from each other. You may ask what's the difference? Well put quite simply if you have a string 001 and 021, the percentage of change is 33% however the difference between the two is 3.7%, Simmilarly with the sets of data 001 and 051, the percentage of change is still 33%, however the difference is now 15%. We're not checking to see what has changed, but rather, how much it has changed from it's original value. While this was primarily deigned to compare the difference between two colors, you could get the relative difference between any two sets of data. This can also be used to see how random an output is. I'm sure other's will think of interesting uses too! The example below creates two random 1000x1000 pixel images and compares them. You'll notice the output is always around 34%, this means that the random() function is only about 34% random! Example: Global $pixelseed = StringSplit('0123456789abcdef', ""), $image1, $image2 for $i=1 to 2000 ;let's make a 1000x1000 pixels image $image1 &= $pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)] $image2 &= $pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)]&$pixelseed[Random(1, $pixelseed[0], 1)] Next $timer = TimerInit() $compare = _datacompare($image1, $image2) ConsoleWrite($compare&'% Different'&@CRLF&'Took '&(TimerDiff($timer)/1000)&' seconds.'&@CRLF) Functions: #cs Function _datacompare($data1, $data2, [$declimal]) -$data1: A string of data, any length. -$data2: A string of data, must be the same length as $data1 -$decimal: 1=Binary 9=Base-10, 15=Base-16, 31=Base-32 Note: If you just want to compare two sets of binary data you probably want to use base-16. Unless you are sure your binary is in 1's and 0's. Returns: A float containing the percentage of difference. #ce func _datacompare($data1, $data2, $decimal=15) Local $difference $data1 = StringSplit($data1, "") $data2 = StringSplit($data2, "") $difference = 0 for $i=1 to $data1[0] if $data1[$i] <> $data2[$i] Then $difference += Abs(_tonum($data1[$i]) - _tonum($data2[$i])) EndIf Next $difference = (($difference/$data1[0])/$decimal)*100 Return $difference EndFunc #cs Function _tonum() -$info: A single digit or carachter. Returns: A 0-based value. #ce func _tonum($info) if $info+0 > 0 Then Return $info $info = StringLower($info) $return = asc($info)-87 switch $return Case -39 Return 0 Case Else Return $return EndSwitch EndFunc Comments, questions, criticisms, improvements? Post them! This is pretty slow right now, about 60 seconds on a 1000x1000 image. I would really like to get it working faster for more practice uses. And help is much appreciated!
- 5 replies
-
- data compare
- binary compare
-
(and 2 more)
Tagged with:
-
If you need to compare two files using WinMerge, you can use the _WinMergeCompare2Files function as in the following example: _Example() Func _Example() FileCopy(@ScriptFullPath, @ScriptFullPath & '.txt') FileWrite(@ScriptFullPath & '.txt', @CRLF & 'TEST' & @CRLF & @CRLF) _WinMergeCompare2Files(@ScriptFullPath, @ScriptFullPath & '.txt') EndFunc ;==>_Example Func _WinMergeCompare2Files($sLeftFilePath, $sRightFilePath, $fWaitForWinMerge = True) ; Left is orginal , Right is new Local Const $sWinMergeParamsKey = 'HKEY_CURRENT_USER\Software\Thingamahoochie\WinMerge' If FileExists($sLeftFilePath) And FileExists($sRightFilePath) Then Local Const $sWinMergeExecutable = RegRead($sWinMergeParamsKey, 'Executable') Local Const $sFileName = StringRegExp($sLeftFilePath, '(?i).*\\(.*)', 3)[0] Local Const $sWinMergeParams = _ ' /u /e /xq /wl /maximize /dl "Original: ' & $sFileName & '" /dr "New version: ' & $sFileName & '" ' & _ '"' & $sLeftFilePath & '"' & ' ' & '"' & $sRightFilePath & '"' If $fWaitForWinMerge Then ShellExecuteWait($sWinMergeExecutable, $sWinMergeParams) Else ShellExecute($sWinMergeExecutable, $sWinMergeParams) EndIf EndIf EndFunc ;==>_WinMergeCompare2Files
- 2 replies
-
- WinMerge
- File compare
-
(and 1 more)
Tagged with:
-
I have very minimal knowledge of AutoIt. I come from basic/batch/vbscript/wisescript environment. I am learning AutoIt as I type this. I'm hoping someone can help me out / point me in the right direction. AutoIt has helped me in the past with many tasks. Again, I am a beginner here. I'm looking for a script that compares two text files (contains listing of files) and sorting out the differences. Once the differences have been sorted out, I want to delete the files that are "different." For example: [file1.txt content] c:dog.txt c:cat.txt c:mouse.txt [file2.txt content] c:dog.txt c:cat.txt c:mouse.txt c:bear.txt Logic: Difference = c:bear.txt Delete c:bear.txt Any help would be appreciated. -DS
-
I wonder if it would be possible for autoit to obtain data from clipboard and compare it with a "notepad file" or something. And if there is a match then it must replace the word with the other word that is behind the = mark. Example: 1. I copy: "car accident" 2. The program must read this. 3. Search through a database. DATABASE(notepad?): car accident = dial 1124. Match? then copy data behind the = mark to clipboard.copy dial 112 to clipboard in this example5. Then if you perform the windows PASTE function then "dial 112" must appear. Thanks in advance, Jeanpierre