Sign in to follow this  
Followers 0
keilamym

"help" - ini read creation / concept ?

4 posts in this topic

im hoping someone can guide me in the right direction.. i have a tool i created in autoit but portions of the script have hard coded paths. What I'd like to do is move these hard-coded paths to an ini file that the script can simply pull from but im not sure the best method/commands. If has any quick examples or suggestions, please let me know.. i'd really appreciate it.

Share this post


Link to post
Share on other sites



See IniRead() and IniWrite() in the help file. There are example scripts there.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

See IniRead() and IniWrite() in the help file. There are example scripts there.

:graduated:

awesome.. i think i got it figured out.. thanks again...

Share this post


Link to post
Share on other sites

Global $inifile = @ScriptDir & "\myinifile.ini"
Global $publicnetworkdrive
Global $personalnetworkdrive

; Check to see if ini file exists
If FileExists($inifile) = 0 Then
    ; No file exists - so show msgbox and create the ini file
    MsgBox(0, "Missing INI", "No INI File")
    CreatePaths()
EndIf

GetPaths() ; Check INI file for paths

If $publicnetworkdrive = "None" or $personalnetworkdrive = "None" Then ;If any keys are missing it'll pickup None
    ; Display msgbox and recreate file
    MsgBox(0, "Missing a path in INI", "Missing a path in INI file - recreating")
    CreatePaths()
    GetPaths() ; Recheck
EndIf

; Display MsgBox with info.
MsgBox(0, "Information", $personalnetworkdrive & " is the personal drive" & @CRLF & $publicnetworkdrive & " is the public drive")

Func CreatePaths() ; IniWrite used to create the file and add section/keys.
    IniWrite($inifile, "Paths", "PublicNetworkDrive", "P:\")
    IniWrite($inifile, "Paths", "PersonalNetworkDrive", "Z:\")
EndFunc

Func GetPaths() ; IniRead used to read the file.  
    $publicnetworkdrive = IniRead($inifile, "Paths", "PublicNetworkDrive", "None")
    $personalnetworkdrive = IniRead($inifile, "Paths", "PersonalNetworkDrive", "None")
EndFunc

IniWrite will create the file and IniRead will auto fill in the variable if it can't read the key. An example is above with limited error control (ie - you could get it to the point where it only creates the keys that are missing, etc).

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