AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Read and write INI files

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
rd2010



Joined: 31 Jan 2010
Posts: 5

PostPosted: Sun Jan 31, 2010 4:18 pm    Post subject: Read and write INI files Reply with quote

How do you read all keys in IniRead?
Back to top
View user's profile Send private message
answer4u
Guest





PostPosted: Sun Jan 31, 2010 4:39 pm    Post subject: Reply with quote

I don't think IniRead has a built-in method for reading all the keys. You could either get creative and find a way to get all the keys ( ie FileRead ), or find a user created INI Library.
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Jan 31, 2010 4:41 pm    Post subject: Reply with quote

Some users reported bugs in Titans library so something more recent might be better, http://www.autohotkey.com/forum/topic46226.html (also has links to other working libraries in the documentation)
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
rd2010



Joined: 31 Jan 2010
Posts: 5

PostPosted: Sun Jan 31, 2010 5:01 pm    Post subject: Reply with quote

I appreciate the fast replys from ya'll. I have been digging and digging with no solution. I have found several scripts but do not know how to specify the file to read from. Here is one:

Code:

ReadIni( filename = 0 )
; Read a whole .ini file and creates variables like this:
; %Section%%Key% = %value%
{
Local s, c, p, key, k

   if not filename
      filename := SubStr( A_ScriptName, 1, -3 ) . "ini"

   FileRead, s, %filename%

   Loop, Parse, s, `n`r, %A_Space%%A_Tab%
   {
      c := SubStr(A_LoopField, 1, 1)
      if (c="[")
         key := SubStr(A_LoopField, 2, -1)
      else if (c=";")
         continue
      else {
         p := InStr(A_LoopField, "=")
         if p {
            k := SubStr(A_LoopField, 1, p-1)
            %key%%k% := SubStr(A_LoopField, p+1)
         }
      }
   }
}
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Sun Jan 31, 2010 5:44 pm    Post subject: Reply with quote

you need to call that function from your code

Code:
myinifile := "thefileIwant.ini"

ReadIni(myinifile )
listvars
pause

_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
rd2010



Joined: 31 Jan 2010
Posts: 5

PostPosted: Sun Jan 31, 2010 6:04 pm    Post subject: Reply with quote

Dude, Thanks.
I am getting there.
Is there any way to make it over look a > as an illegal character?
Back to top
View user's profile Send private message
rd2010



Joined: 31 Jan 2010
Posts: 5

PostPosted: Sun Jan 31, 2010 6:22 pm    Post subject: Reply with quote

Sorry that wasn't what I needed to ask.
My INI file keys have the same name, so the script is complaining after the first key:

Error:the following variable name contains an illegal character "roomsconf"

myINI file:
[rooms]
conf => 600
conf => 601
conf => 602
Back to top
View user's profile Send private message
rd2010



Joined: 31 Jan 2010
Posts: 5

PostPosted: Wed Feb 03, 2010 5:15 pm    Post subject: Reply with quote

engunneer wrote:
you need to call that function from your code

Code:
myinifile := "thefileIwant.ini"

ReadIni(myinifile )
listvars
pause


Dude, Thanks.
I am getting there.
Is there any way to make it over look a > as an illegal character?

Sorry that wasn't what I needed to ask.
My INI file keys have the same name, so the script is complaining after the first key:

Error:the following variable name contains an illegal character "roomsconf"

myINI file:
[rooms]
conf => 600
conf => 601
conf => 602
Back to top
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Wed Feb 03, 2010 5:40 pm    Post subject: Reply with quote

myINI file:
[rooms]
conf => 600
conf => 601
conf => 602[/quote]

Why =>? Is it a specific INI format you have to use?

As I understood it and wiki questionably confirms:
Quote:

Format

Parameters

The basic element contained in an INI file is the parameter. Every parameter has a name and a value, delimited by an equals sign (=). The name appears to the left of the equals sign.

name=value


Sorry if I'm off base, haven't worked with INI in AHK yet.
Back to top
View user's profile Send private message
Tuncay n-l-i mobile
Guest





PostPosted: Wed Feb 03, 2010 5:57 pm    Post subject: Reply with quote

search in this forum for "Basic ini string functions". I am not at home now. Later i show u how to get what u want
Back to top
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Wed Feb 03, 2010 7:54 pm    Post subject: Reply with quote

So, I am at home now (may be you guessed right, I am the guest above). Oh I see Hugov has linked to the Basic Ini string library already.^^ cool Hugov Very Happy

ini_getValue()

With that library you dont need to set global variables for each kez. It provides functions to read keys from variables with the content of ini files. If you do not convert each key into variable, then it can have nearly any character in name. Look in the examples:
  1. For example you load the whole file into a variable named "ini":
    Code:
    inipath := ini_load(ini, "filename.ini")

  2. Then you can read in example one keys content:
    Code:
    value := ini_getValue(ini, "rooms", "conf")
    MsgBox %value%


ini_exportToGlobals()

It can create global variables for each key also, if needed:
Code:
ini_exportToGlobals(ini, 0)
ListVars
Msgbox % ini_RecentFileList_File2

Quote:
Remarks:
Creates global variables from ini source. The scheme for building the variables is
following:

> Prefix + Seperator + SectionName + Seperator + KeyName
> ini + _ + Tip + _ + TimeStamp
> --------------------------------------------------------------
> ini_Tip_TimeStamp := "20090716194758"

Standard prefix to every variable is "ini" and all parts are delimited by the
separator "_". The SectionSpaces parameter deletes at default every space from
name of section, because spaces inside ahk variable names are not allowed.


It is the best you show your script and explain in detail what you want and need. And show us part of the ini file content. The given example of you is in no way a widely used ini file format. So, the library does not handle that.
_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group