FileRead does not get whole file Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
buxnaman
Posts: 3
Joined: 18 Jul 2018, 13:22

FileRead does not get whole file

18 Jul 2018, 14:49

Hello everyone,

I am trying to retrieve text from a web page and manipulate it. I use UrlDownloadToFile to download the page, which works perfectly, but when I try and use FileRead on it, it only loads it partially. The worst thing is it worked as it should and then out of the blue just started cutting the text off. I honestly can't figure out what went wrong, can you please help?

As I couldn't upload files directly, being a possible attack vendor :lol: , I was forced to use PasteBin. You can view the file that I run FileRead on https://pastebin.com/ZiT83rKH and the content of the variable, the cut off text on https://pastebin.com/VYYXc0wi

Any ideas? I can post my whole script as well, but I don't think it makes any difference. Thanks in advance.
trust_me
Posts: 47
Joined: 29 Jul 2017, 10:46

Re: FileRead does not get whole file

20 Jul 2018, 05:44

You could try to download it to a variable instead of a file.

from the help on urldownloadToFile command:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

; Example: Download text to a variable:
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://autohotkey.com/download/1.1/version.txt", true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
version := whr.ResponseText
MsgBox % version
buxnaman
Posts: 3
Joined: 18 Jul 2018, 13:22

Re: FileRead does not get whole file

20 Jul 2018, 08:36

trust_me wrote:You could try to download it to a variable instead of a file.

from the help on urldownloadToFile command:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

; Example: Download text to a variable:
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://autohotkey.com/download/1.1/version.txt", true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
version := whr.ResponseText
MsgBox % version


Thanks for the suggestion, I did, but I get the exactly same result.

That's how the issue started happening in the first place, so I moved to saving to a file and FileRead-ing the file to realize it's where it happens as well.
Can someone try and FileRead the attached file and report if you get the same result as I?

Thanks again.
trust_me
Posts: 47
Joined: 29 Jul 2017, 10:46

Re: FileRead does not get whole file  Topic is solved

20 Jul 2018, 09:40

It works for me but maybe if you display it using a msgbox it exceeds the max number of characters for a messagebox.
If you display the last characters you can see it is the end of the file.

Code: [Select all] [Download] (test_filetovar.ahk)GeSHi © Codebox Plus

sfile=ZiT83rKH.txt
FileRead, data,%sfile%
filegetsize,len,%sfile%
msgbox % strlen(data) "`n" len
MsgBox, % substr(data,-250)
buxnaman
Posts: 3
Joined: 18 Jul 2018, 13:22

Re: FileRead does not get whole file

06 Aug 2018, 21:24

trust_me wrote:It works for me but maybe if you display it using a msgbox it exceeds the max number of characters for a messagebox.
If you display the last characters you can see it is the end of the file.

Code: [Select all] [Download] (test_filetovar.ahk)GeSHi © Codebox Plus

sfile=ZiT83rKH.txt
FileRead, data,%sfile%
filegetsize,len,%sfile%
msgbox % strlen(data) "`n" len
MsgBox, % substr(data,-250)


It was a stupid error down the line in the code that was causing issues all along. Thanks for your help!!!!

Return to “Ask For Help”

Who is online

Users browsing this forum: Hellbent, ZeroX4 and 66 guests