Sign in to follow this  
Followers 0
Shinies

Reading a .txt file

5 posts in this topic

Hey, i have been trying to get the text inside a .txt file, and storing it into a $var. I was using this code to test if it would work

$fileread = FileOpen("123.txt", 0)
If $fileread = -1 Then 
Exit
EndIf
While 1
    $txt = FileRead($fileread, 1)
    If @error = -1 Then ExitLoop
Wend
FileClose($fileread)

Run("Notepad.exe")
WinWaitActive("Untitled - Notepad")
Send($txt)

But all it writes to the notepad is "¼" ..? is there another function i can use to accomplish this? or is there another way to do this? plz help

thanks

-Smirk ;)

Share this post


Link to post
Share on other sites



Try The Following:

$file = FileOpen("test.txt", 0)
$cnt = FileGetSize("Test.txt")
If $file = -1 Then 
Exit
EndIf
$txt = FileRead($file, $cnt)
ClipPut($txt)
FileClose($file)

Run("Notepad.exe")
WinWaitActive("Untitled - Notepad")
;Send($txt);Uncomment this line to send the text one character at a time
;Send("^v");Uncomment this line to paste the text into notepad all at once

We have enough youth. How about a fountain of SMART?

Share this post


Link to post
Share on other sites

why not just use

$txt = FileRead('test.txt', FileGetSize('test.txt'))

If @error then Exit

clipput($txt)

and... if you'd like to read just one line at a time, check out: FileReadLine ( filehandle or "filename" [, line] )

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

The first one worked perfectly, i spose where i went wrong was not getting the file size? anyways, thank you so much for your help

-Smirk

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