Jump to content

comparing parts of files


Recommended Posts

since i learned about FileWrite i decided to use it as an idea for an eye.

what i need to learn is how to compare one .txt file to another. or more specifically, PARTS of another.

suggestions please?

There are a couple of functions in the AutoIT Help file that do this. Try:

FileRead

FileReadLine

_FileReadToArray

[font="Times New Roman"]Ocho.[/font]
Link to comment
Share on other sites

use _FileReadToArray so you get an array of line to load both files then they will both be stored in your program in the same format, then use StringMid() to select the part of each specific line that you want and use If $a == $b then to compare them. you could also use StringCompare() which would tell you if they are the same or if one has a higher value than the other.

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Link to comment
Share on other sites

-_______-;

if course. if there's FileWrite, then there HAS to be FileRead. i feel stupid now.

i'm having trouble understanding the example from the helpfile though. (about _FileReadToArray)

it would be great if you spent another 5 minutes or so to write me an example you would use to teach a retard with. thank you in advance.

Link to comment
Share on other sites

Dim $array[1]
_FileReadToArray(@ScriptDir & "\file.txt", $array)

MsgBox(0, "no of lines", $array[0])
MsgBox(0, "line 1", $array[1])

Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Link to comment
Share on other sites

Dim $array[1]
_FileReadToArray(@ScriptDir & "\file.txt", $array)

MsgBox(0, "no of lines", $array[0])
MsgBox(0, "line 1", $array[1])
and finally, tell me if i got it right, please. i want to be sure i understand this. i want to compare these two files.

dim $arrayone[1]
dim $arraytwo[1]

_FileReadToArray(@ScriptDir\Data&"colordump1.txt", $arrayone[1])
_FileReadToArray(@ScriptDir\Data&"colordump.txt, $arraytwo[1])

if $arrayone[1] == $arraytwo[1] then
<insert more code. too lazy to make up more>

i need to compare the two files to see if they're IDENTICAL.

Link to comment
Share on other sites

if you need to see if they are exactly identical then you can use

$file1 = FileRead(@ScriptDir & "\file1.txt")
$file2 = FileRead(@ScriptDir & "\file2.txt")

$same = StringCompare($file1, $file2)

If $same Then
;code
Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Link to comment
Share on other sites

_FileReadToArray(@ScriptDir\Data&"colordump1.txt", $arrayone[1])

_FileReadToArray(@ScriptDir\Data&"colordump.txt, $arraytwo[1])

Almost right, but I think these two lines should be:

_FileReadToArray(@ScriptDir & "\Data" & "\colordump1.txt", $arrayone[1])

_FileReadToArray(@ScriptDir & "\Data" & "\colordump.txt, $arraytwo[1])

If your files are set up the way I think they are being set up.

[font="Times New Roman"]Ocho.[/font]
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...