Jump to content

How to expand AutoIT Variables when read from a config file


Recommended Posts

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 :)

Link to comment
Share on other sites

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

 

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...