Sign in to follow this  
Followers 0
cbroui

reading a text file

7 posts in this topic

I want to read a line of text out of a text file. I have tried opening a text file copied straight from the help file and it also fails to open. The file does exist, I have tried with the file in the same directory and hard coding a path. What am I missing?

CODE
$file = FileOpen("test.txt", 0)

FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $line)

Wend

FileClose($file)

I have a newly created test.txt file in the same directory. I have also tried this on 3 separate WinXP machines and it always returns "Unable to open file" msg.

Share this post


Link to post
Share on other sites



I want to read a line of text out of a text file. I have tried opening a text file copied straight from the help file and it also fails to open. The file does exist, I have tried with the file in the same directory and hard coding a path. What am I missing?

CODE
$file = FileOpen("test.txt", 0)

FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $line)

Wend

FileClose($file)

I have a newly created test.txt file in the same directory. I have also tried this on 3 separate WinXP machines and it always returns "Unable to open file" msg.

You've got two FileOpen statements in your code.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

You've got two FileOpen statements in your code.

Even that does not stop it working for me.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The code was copied straight out of the help file for FileReadLine. It failed and i can not understand why. So I reread the code and thought 'maybe it is not opening because I did not tell it to open. Line one assigns the open command into a variable but does not execute it.' So I added a second open statement to be sure the command to open was executed. Still no luck.

If it were just happening on one machine I would think it is my OS or policy or something local. I can not get a file to read on any machine using any command from V3. I have used Autoit V2 extensively and never had issues using any of the supplied commands. Can you copy the exact script I posted, drop it on AutoIt3.exe and the file opens successfully?

Edited by cbroui

Share this post


Link to post
Share on other sites

I just copied and pasted the text into an au3 file and ran it just fine. Are you sure the test.txt is in the same directory as your au3 file?

Share this post


Link to post
Share on other sites

I just copied and pasted the text into an au3 file and ran it just fine. Are you sure the test.txt is in the same directory as your au3 file?

Yes. And I can not stress enough how aggravating this is. I can even copy the script and AutoIt3.exe to the desktop of a freshly imaged PC and create a new text document named test.txt with one line of text in it. SAME THING. I have to be doing something wrong. I have even tried creating a temp folder on the root of my drive, placed the three files in it and hardcoded the path. It refuses to open. I have downloaded a new copy of AutoIt3.exe just because I can not think of anything else to try. Same issue. I feel like I am on crazy pills.

Share this post


Link to post
Share on other sites

Hooray! I am not insane.

Apparently V3 of Autoit is not fully drag and drop compatible like V2 was. If you drag and drop the script onto your AutoIt3.exe you will reproduce my frustration. The script runs as in you get the msgbox telling you the file did not open, but the Fileopen fails. If you tell Windows to run your script with AutoIt3.exe it works as designed. Thanks for the quick responses and I hope the next person going out of their mind finds this before they give up on the new version.

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