Jump to content
Sign in to follow this  
bcording

Expanding Environment Vars

Recommended Posts

bcording

So lets say you are reading an INI file. You read an item that is "%ComSpec%". The AutoIt option ExpandEnvStrings does not effect this since it's read from a file. I know you could use EnvGet to get the variable. But what about if from the INI you read "%.%temp%.%comspec%.%bob%.%.%". Does anyone have a UDF to expand this?

Thanks

Share this post


Link to post
Share on other sites
SlimShady

The first line is an example...

MsgBox(0, "", "%COMSPEC% = " & ParseEnvVar("%COMSPEC%"))

   Func ParseEnvVar($EnvVar)
       $var = StringMid($EnvVar, 2, StringLen($EnvVar) - 2)
       Return EnvGet($var)
   EndFunc
Edited by SlimShady

Share this post


Link to post
Share on other sites
bcording

Thanks Slim, but that really dosn't help too much. I figured it out this morning when i sobered up. This function will expand all the environment variables in a string.

Func ExpandEnvVars($Cooked)
    Local $Split, $i, $Expanded
    $Split = StringSplit($Cooked,"%")
    
    For $i = 1 To $Split[0]
        $Expanded = EnvGet($Split[$i])
        If $Expanded <> "" Then
            $Cooked = StringReplace($Cooked,"%" & $Split[$i] & "%", $Expanded)
        EndIf
    Next

    Return $cooked
EndFunc

Share this post


Link to post
Share on other sites
this-is-me

I'm pretty sure I don't want to know, but what in the world does your avatar show? An alien? :ph34r:


Who else would I be?

Share this post


Link to post
Share on other sites
bcording

A very close up picture, with flash, of my chihuahua.

Share this post


Link to post
Share on other sites
this-is-me

Is the top part a piece of his eye?


Who else would I be?

Share this post


Link to post
Share on other sites
bcording

Left hand bottom corner is her nose. The cool looking alien eye is her eye.

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
Sign in to follow this  

×