Jump to content

Help with getting text from a file


Recommended Posts

I am trying to get startup programs for windows using somthing that can be automated without having the user see anything. i am using MSINFO32 with some switches to generate a log file that has the startup programs, along with all the startuo dlls and whatnot which i don't want. so in my script i have the following text

_Filereadtoarray($MSINFO, $MSINFOArray)

_ArrayReverse($MSINFOArray)

_arraySort($MSINFOArray)

for $i = 0 to 25 Step 1

filewriteline("c:\test.txt", _arraybinarySearch($MSINFOArray, "exe"))

Next

what im trying to do is first reverse the array because the data i need is at the very bottom of the file, then im tryign to take the first 25lines and write it to my file (test.txt for testing purposes)

i tried to display the values being written to teh array but i get these as the values

[0] = 1

[1] = y(with dots over it)(some wierd B)S

so i figure the array is wrong or somthing.... i tried to get the number of lines in the file generated but i get a negitive number for some reason.... but i don't know why its doing that, because i don't need to use a array, i just want the last few lines of this file, but i can't get ht number of lines to come out right... im guessing its the file being generated, but like i said there is nothing odd about it...

if your wondering what command im using to get this file, it is this in the run box

"C:\Program Files\Common Files\Microsoft Shared\MSInfo\MSInfo32.exe" /report C:\msinfo.txt /categories +swenvstartupprograms

this is how i have my array Dimed (up witht e global variables)

Dim $MSINFOArray

(if i put a [] it errors for some reason, but i don't want to have the size limited i guess)

does anyone have any ideas?

thanks

Link to comment
Share on other sites

are you trying to read a binary file (exe, dll, etc.)

i don't believe so, i specifiy the file to be a txt file when i run shte MSINFO32 command, the output it generates is in the form of a txt file, which i use in the code

Link to comment
Share on other sites

I have no experience with arrays and am trying to understand what you are doing for my own benefit as well, so I am making heavy use of the help file. First of all it seems to me that the line

_arraySort($MSINFOArray)

messes up the effect of the previous line

_ArrayReverse($MSINFOArray)

and in fact if you are sorting the array you may as well sort the initial array as the result should be the same. I think you may need somehow extract the first 25 lines from the reversed array into a new array, sort that and then try sorting out which lines contain "exe"

Secondly in your _ArrayBinarySearch line Don't you need to specify a starting index. Your loop seems to be simply doing the same thing each time. The result of _ArrayBinarySearch is a key number specifying which element of the array contains the "exe" so in order to write that element to a file you need to specify which array element you are writing.

$MSINFOArray[_arraybinarySearch($MSINFOArray, "exe")]

Link to comment
Share on other sites

I have no experience with arrays and am trying to understand what you are doing for my own benefit as well, so I am making heavy use of the help file. First of all it seems to me that the line

_arraySort($MSINFOArray)

messes up the effect of the previous line

_ArrayReverse($MSINFOArray)

and in fact if you are sorting the array you may as well sort the initial array as the result should be the same. I think you may need somehow extract the first 25 lines from the reversed array into a new array, sort that and then try sorting out which lines contain "exe"

Secondly in your _ArrayBinarySearch line Don't you need to specify a starting index. Your loop seems to be simply doing the same thing each time. The result of _ArrayBinarySearch is a key number specifying which element of the array contains the "exe" so in order to write that element to a file you need to specify which array element you are writing.

$MSINFOArray[_arraybinarySearch($MSINFOArray, "exe")]

i know what ur saying with the sorting and whatnot, but my error seems to occur on the this line

_Filereadtoarray($MSINFO, $MSINFOArray)

because it displays the array right after i read it in in my code, and the values i get are those 2 garbled ones. so i can't even sort it wrong because it isn't even being read correctly

Link to comment
Share on other sites

  • Moderators

You could try to debug a bit:

If _Filereadtoarray($MSINFO, $MSINFOArray) Then
;_ArrayReverse($MSINFOArray)
;_arraySort($MSINFOArray)
    For $i = UBound($MSINFOArray) - 1 To 1 Step - 1
        MsgBox(0, 'Test', $MSINFOArray[$i])
;filewriteline("c:\test.txt", _arraybinarySearch($MSINFOArray, "exe"))
    Next
Else
    MsgBox(0, 'Error', 'Problem reading file path, might not exist')
EndIf
In your example your not using the For/Next Loop correctly... Should be $MSINFOArray[$i], not $MSINFOArray.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You could try to debug a bit:

If _Filereadtoarray($MSINFO, $MSINFOArray) Then
;_ArrayReverse($MSINFOArray)
;_arraySort($MSINFOArray)
    For $i = UBound($MSINFOArray) - 1 To 1 Step - 1
        MsgBox(0, 'Test', $MSINFOArray[$i])
;filewriteline("c:\test.txt", _arraybinarySearch($MSINFOArray, "exe"))
    Next
Else
    MsgBox(0, 'Error', 'Problem reading file path, might not exist')
EndIf
In your example your not using the For/Next Loop correctly... Should be $MSINFOArray[$i], not $MSINFOArray.
hmm i tried the code you provided, i get a 1 as my messagebox which im guessing means its not a array from what i read under ubound.... which is wierd... do i have to do somthing to make it a array? i did the dim statement, and whatnot

--hmm this is interesting, im working with reading the number of lines in that document i want to put into teh array maybe, and it doesn't work if i use the org file, or make a direct copy of it, but if i open the file and copy the contents it reads the number of lines fine.... but i don't see anything special in teh document that would screw up a line count

Edited by fox_91
Link to comment
Share on other sites

  • Moderators

hmm i tried the code you provided, i get a 1 as my messagebox which im guessing means its not a array from what i read under ubound.... which is wierd... do i have to do somthing to make it a array? i did the dim statement, and whatnot

--hmm this is interesting, im working with reading the number of lines in that document i want to put into teh array maybe, and it doesn't work if i use the org file, or make a direct copy of it, but if i open the file and copy the contents it reads the number of lines fine.... but i don't see anything special in teh document that would screw up a line count

Must admit... now I'm confused, why not upload a copy of the file your wanting to read.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Must admit... now I'm confused, why not upload a copy of the file your wanting to read.

well i might be getting it close now... there must be some wierd character screwing up copies or somthing, i had to run a dos command, using more, and redirecting it to a seperate file, now i can copy it back and get the correct number of lines.... which i might just use the lines to do some simple math and grab the last 25 lines instead of using arrays, unless it works easy now.... thanks for helping me.. turns out of be the stupid file screwing it up :o

Link to comment
Share on other sites

  • Moderators

well i might be getting it close now... there must be some wierd character screwing up copies or somthing, i had to run a dos command, using more, and redirecting it to a seperate file, now i can copy it back and get the correct number of lines.... which i might just use the lines to do some simple math and grab the last 25 lines instead of using arrays, unless it works easy now.... thanks for helping me.. turns out of be the stupid file screwing it up :o

Ha, don't feel that I helped out any... but ok. I don't see a character screwing up _FileReadToArray(), are you trying to read a URL? Well if you run into problems, post what you've done and what has failed, and post an example URL and or Text file so that the situation can be re-created and I'm sure someone can/will work it out with you.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...