OhBobSaget

How to expand AutoIT Variables when read from a config file

4 posts in this topic

#1 ·  Posted

Hi everyone!

 

I am having problems with AutoIT variables stored in a config file.

When i start the application, first i want it to read all the parameters in a config.ini file.

I read from the ini file into a variable:

Here's one line in the config file :

pathPDFInfo = @ScriptDir &"\pdfinfo.exe"

In the AutoIt script i get this information with IniRead :

Global Const $pathPDFInfo = IniRead(@ScriptDir & "\config.ini","PDFnWatermark","pathPDFInfo ","")

I would like to know how to expand autoIT variables so my variable would be dynamic.

For the moment is i do consolewrite(pathPDFInfo) i get @ScriptDir &"\pdfinfo.exe" but i would prefer that @ScriptDir to resolve to the folder where the script is located.

Any idea ?

 

Thank you :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can use Execute(IniRead(...)) example:

Global $pathPDFInfo = Execute(IniRead(@ScriptDir & "\config.ini","PDFnWatermark","pathPDFInfo ",""))

 

Edited by Subz

Share this post


Link to post
Share on other sites

#3 ·  Posted

Forgot to mention I sometimes use the following:

In the ini file I'd use:

pathPDFInfo = @ScriptDir@\pdfinfo.exe

Then use option ExpandVarStrings

Opt("ExpandVarStrings", 1)
Global pathPDFInfo = IniRead(@ScriptDir & "\config.ini","PDFnWatermark","pathPDFInfo ","")
Opt("ExpandVarStrings", 0)

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

26 minutes ago, Subz said:

Forgot to mention I sometimes use the following:

In the ini file I'd use:

pathPDFInfo = @ScriptDir@\pdfinfo.exe

Then use option ExpandVarStrings

Opt("ExpandVarStrings", 1)
Global pathPDFInfo = IniRead(@ScriptDir & "\config.ini","PDFnWatermark","pathPDFInfo ","")
Opt("ExpandVarStrings", 0)

 

Thank you !

Using Opt("ExpandVarStrings", 1) and putting a @ at the begining and end of the string did it !

I will then discard this... since yours is better :)

Func ExpandAutoITStringVariables($pathToVerify)
    Local $variableAutoITaExpand[] = ["@ScriptDir","@UserProfileDir","@WindowsDir","@ProgramFilesDir","@DesktopDir","@AppDataDir","@HomeDrive"]
    Local $equivAutoITExpanded[] = [@ScriptDir,@UserProfileDir,@WindowsDir,@ProgramFilesDir,@DesktopDir,@AppDataDir,@HomeDrive]
    For $i = 0 to UBound($variableAutoITaExpand) -1
        If StringInStr($pathToVerify,$variableAutoITaExpand[$i],$STR_NOCASESENSE)>0 Then
            $pathToVerify = StringReplace($cheminAVerfier,$variableAutoITaExpand[$i],$equivAutoITExpanded[$i])
        EndIf
    Next
    Return $pathToVerify
EndFunc

 

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