OhBobSaget Posted April 28, 2017 Posted April 28, 2017 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
Subz Posted April 28, 2017 Posted April 28, 2017 (edited) You can use Execute(IniRead(...)) example: Global $pathPDFInfo = Execute(IniRead(@ScriptDir & "\config.ini","PDFnWatermark","pathPDFInfo ","")) Edited April 28, 2017 by Subz
Subz Posted April 28, 2017 Posted April 28, 2017 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)
OhBobSaget Posted April 28, 2017 Author Posted April 28, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now