Jump to content

"help" - ini read creation / concept ?


keilamym
 Share

Recommended Posts

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.

Link to comment
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).

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...