Jump to content
Sign in to follow this  
GodForsakenSoul

comparing parts of files

Recommended Posts

GodForsakenSoul

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?

Share this post


Link to post
Share on other sites
OchoNueve

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]

Share this post


Link to post
Share on other sites
FaT3oYCG

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.

Share this post


Link to post
Share on other sites
GodForsakenSoul

-_______-;

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.

Share this post


Link to post
Share on other sites
FaT3oYCG

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.

Share this post


Link to post
Share on other sites
GodForsakenSoul

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.

Share this post


Link to post
Share on other sites
FaT3oYCG

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.

Share this post


Link to post
Share on other sites
OchoNueve

_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]

Share this post


Link to post
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
Sign in to follow this  

×