Is there a more efficient way to read keys from an ini file using FileRead or FileReadLine instead of iniRead? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Is there a more efficient way to read keys from an ini file using FileRead or FileReadLine instead of iniRead?

08 Apr 2021, 06:01

So if FileAppend can be used more efficiently than IniWrite

Example:

Code: Select all

FileAppend, [section1] `nClass=%Class% `nX=%X% `nY=%Y% `nWidth=%Width% `nHeight=%Height%, LastWindowSeen.ini
Instead of

Code: Select all

IniWrite, %Class%, LastWindowSeen.ini, section1, Class
IniWrite, %X%, LastWindowSeen.ini, section1, X
IniWrite, %Y%, LastWindowSeen.ini, section1, Y
IniWrite, %Width%, LastWindowSeen.ini, section1, Width
IniWrite, %Height%, LastWindowSeen.ini, section1, Height
Is there a more efficient way to read keys from an ini file using FileRead or FileReadLine instead of iniRead?

The only thing I know of is

Example:

Code: Select all

IniRead, Class, LastWindowSeen.ini, section1, Class
IniRead, X, LastWindowSeen.ini, section1, X
IniRead, Y, LastWindowSeen.ini, section1, Y
IniRead, Width, LastWindowSeen.ini, section1, Width
IniRead, Height, LastWindowSeen.ini, section1, Height
instead of

Code: Select all

FileReadLine, Class, LastWindowSeen.ini, 2
FileReadLine, X, LastWindowSeen.ini, 3
FileReadLine, Y, LastWindowSeen.ini, 4
FileReadLine, Width, LastWindowSeen.ini, 5
FileReadLine, Height, LastWindowSeen.ini, 6
However, while FileReadLine appears to be very similar to IniRead, FileReadLine seems like it can be more cumbersome if used to read larger ini files. So, I do not see why anyone would want to use FileReadLine over IniRead if everything cannot be stuck in one line resembling the aforementioned usage regarding FileAppend versus IniWrite, unless there are some tricks I don't know about.
:roll:
User avatar
boiler
Posts: 16981
Joined: 21 Dec 2014, 02:44

Re: Is there a more efficient way to read keys from an ini file using FileRead or FileReadLine instead of iniRead?  Topic is solved

08 Apr 2021, 06:06

Using the file-based commands may allow you to set up the .ini file in fewer lines, but it’s not a good practice in general because it doesn’t update those entries if they already exist. And while it would be possible to read the .ini file and parse it, you would pretty much be rewriting what already exists in the IniRead command. It wouldn’t be more efficient in any sense. You can’t or at least shouldn’t count on the entries appearing in the same order as you showed in your example using FileReadLine. If you’re going to do all that, why use .ini files?
User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Re: Is there a more efficient way to read keys from an ini file using FileRead or FileReadLine instead of iniRead?

08 Apr 2021, 06:16

boiler wrote:
08 Apr 2021, 06:06
Using the file-based commands may allow you to set up the .ini file in fewer lines, but it’s not a good practice in general because it doesn’t update those entries if they already exist. And while it would be possible to read the .ini file and parse it, you would pretty much be rewriting what already exists in the IniRead command. It wouldn’t be more efficient in any sense. You can’t or at least shouldn’t count on the entries appearing in the same order as you showed in your example using FileReadLine. If you’re going to do all that, why use .ini files?
Alright, well that's that I guess. Thank you for the swift response boiler.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], mikeyww, Rohwedder and 256 guests