Sign in to follow this  
Followers 0
saldous

Problem reading string of text from a file

11 posts in this topic

#1 ·  Posted (edited)

I'm trying to parse a file on my hard drive to find some text within it. The file I am trying to read from is an XML file, I don't need to make any changes to the XML, just capture some data from it. I'm unsure if to first open the file in RAW (4) or READ (0) mode? (Read is the only one that seems to do something in my test)

Secondly, I read the file in, then to check it read the correct thing I wanted to simply display what was read on the screen, but this is not returning what I expected, it returns the following:

ÿB<

My code is below, is anyone able to tell me where I've gone wrong? (the xml file only have about 450 characters within it)

Thank you:

CODE
#include <String.au3>

$file = FileOpen("C:\Data.xml",0)

If $file = -1 Then

Msgbox(0,"","Error Opening File")

EndIf

$line = FileRead ($file)

Msgbox(0, "Line Read","" & $line)

$sStart = "<VersionNumber>"

$sEnd = "</VersionNumber>"

$version = _StringBetween ($line, $sStart, $sEnd)

IF $version = 0 Then

Msgbox(0,"","Error Getting Version Number")

Else

EndIf

MsgBox (0,"","The version number is:" & $version)

FileClose("C:\Data.xml")

Edited by saldous

Share this post


Link to post
Share on other sites



Is this an XML file or an EXE file?

Anyway, if the file is in Unicode, you'll need to translate it to ansii. Without the actual file to test, I can only speculate.


[center]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.[/center]

Share this post


Link to post
Share on other sites

Is this an XML file or an EXE file?

Anyway, if the file is in Unicode, you'll need to translate it to ansii. Without the actual file to test, I can only speculate.

The file is XML, I can open it in NotePad and read the plain text fine.

Share this post


Link to post
Share on other sites

The file is XML, I can open it in NotePad and read the plain text fine.

Well, yes of course you can. You can open just about anything up in notepad and read it in notepad :whistle: .

But what type of file is it, is it saved as Unicode, UTF-8, or ANSII?


[center]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.[/center]

Share this post


Link to post
Share on other sites

Well, yes of course you can. You can open just about anything up in notepad and read it in notepad :whistle: .

But what type of file is it, is it saved as Unicode, UTF-8, or ANSII?

I have to admit I don't know how to work this out, I'm happy to email the file to you if you want to PM me your address?

than you for trying to help me.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ok, ignore that, I've found a basic way of solving the file type and reading it in by doing the following:

CODE
RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"')

My script can now read in the text correctly. Yippeee.

Edited by saldous

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I have to admit I don't know how to work this out, I'm happy to email the file to you if you want to PM me your address?

than you for trying to help me.

Actually you can PM me the file if you like or upload it here (probably smarter considering the kids are getting ready for school)... as I said in the PM, not much for going out of my way.

ok, ignore that, I've found a basic way of solving the file type and reading it in by doing the following:

CODE
RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"')

My script can now read in the text correctly. Yippeee.

Good, as I suspected it was probably in Unicode :whistle:

Nice to see someone find their own solution, and actually post that solution :)

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Is there another way to convert it from Unicode though? The only problem with my solution is that there is a very brief DOS box window that appears on the screen, I'd rather it didn't do this, but no major issue if not.

Share this post


Link to post
Share on other sites

Is there another way to convert it from Unicode though? The only problem with my solution is that there is a very brief DOS box window that appears on the screen, I'd rather it didn't do this, but no major issue if not.

RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"', '', @SW_HIDE)
:whistle:

[center]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.[/center]

Share this post


Link to post
Share on other sites

Perfect! :whistle:

Share this post


Link to post
Share on other sites

Perfect! :)

hello saldous

after editin with RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"', '', @SW_HIDE)

can u post ur script to read xml file

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  
Followers 0