Problem with fileread

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Problem with fileread

Post by PuzzledGreatly » 20 Mar 2023, 19:36

Suddenly fileread is not inserting linefeeds unless I use the option *t which help says should be unnecessary. . What could be causing this change in behaviour? I'm only trying to read text files. Thanks.

Edit: I checked two different text files using notepad++ to see the hidden cr and lf characters. Both have the same structure yet fileread is treating the files differently. One is loaded as a single string and the other with linefeeds as expected. This is worrying.

garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Problem with fileread

Post by garry » 21 Mar 2023, 01:54

maybe try with fileopen

Code: Select all

F1 := a_desktop . "\test1.txt"
F2 := a_desktop . "\test2.txt"
aa := FileOpen(F1,"r",UTF-8)
var:= aa.Read()
aa.Close()
FileOpen(F2, "w", "UTF-8").Write(var)
try
 run,%f2%
exitapp
;=========================================

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Problem with fileread

Post by swagfag » 21 Mar 2023, 02:41

u can post the files and the code, then we can see if something is actually wrong

User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Problem with fileread

Post by PuzzledGreatly » 22 Mar 2023, 00:14

Thanks for the replies. Sample code:

Code: Select all

fileread, update, #[settings].txt	
msgbox, 4096, update,% update
fileread, update, *t #[settings].txt	
msgbox, 4096, update,% update
With the attached file the first msgbox has no linefeeds resulting in a long string while the second does.
Attachments
#[settings].txt
(210 Bytes) Downloaded 13 times

just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Problem with fileread

Post by just me » 22 Mar 2023, 05:03

The MsgBoxes look identical here.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Problem with fileread

Post by swagfag » 22 Mar 2023, 05:36

the file contains 2 instances of CRLF in it(yielding 3 lines total)
image.png
image.png (41.69 KiB) Viewed 242 times

the first msgbox shows
image.png
image.png (7.02 KiB) Viewed 242 times
image.png
image.png (37.95 KiB) Viewed 242 times
Image
the second msgbox shows
Image
Image
Image
both MsgBoxes show the same 3 lines. FileRead *t has correctly translated CRLF into LF
ahk 1.1.32.02, all exes

User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Problem with fileread

Post by PuzzledGreatly » 22 Mar 2023, 20:24

Thanks for the replies. On my system I'm only getting three lines with fileread and that file when I use *t. I get a long string when I don't. Could reinstalling AutoHotKey fix this issue? Thanks again.

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Problem with fileread

Post by off » 22 Mar 2023, 20:31

You can try sending screenshot of the msgbox.
Im curious what do you mean by different

I tried your script with your own txt file, same result. Maybe your AHK version? Are you using the newest V1?
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Post Reply

Return to “Ask for Help (v1)”