I am attempting to use a Local variable in a DirCopy command but when I insert the $Variable
into the C:\Users\store$Variable\Desktop
path it attempts to read the path literally instead of using the $Variable.
The objective is to create a prompt for the Store number and insert that number into a bunch of DirCopy lines to ensure we get the profiles that contain only that number. The issue is that the profiles are one word, ex. store123, reciever123.
This is what I put together so far but I can't get it to take the variable in this way.
Local $STORE = InputBox ( "Store Number" , "What Store is This?" )
DirCopy ( "\\192.168.1.3\C$\Documents and Settings\store$STORE\Desktop" , "C:\Users\Store$STORE\desktop" )
DirCopy ( "\\192.168.1.3\c$\Documents and Settings\Profile$STORE\Desktop" , "C:\Users\Profile$STORE\Desktop")
Is there a formatting issue? or is this not possible in AutoIT?
In order to use Variables inside strings, you need to concatenate them, by using the &
operator:
$nVar = 42
$sStr = "Hello, " & $nVar & "World!"
; $sStr will now hold: "Hello, 42World!"
However, there is a Opt()
flag ExpandVarStrings
that enables inline variable use:
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
$nVar = 42
$sStr = "Hello, $nVar$World!"
; $sStr contains: "Hello, 42World!"