8

I am trying to read in from a file where a folder path is specified using environment variable shortcuts, like the following:

source          dest
filename.ext    %programfiles(x86)%\FolderName\

I get the following error when trying to use Path.Combine() to concatenate this with a filename:

"Could not find a part of the path %programfiles(x86)%\FolderName\filename.ext"

Do I have to parse environment variables (like %programfiles(x86)% and %appdata%) out and manually replace them, or is there a another way to have these resolved? Seems like a common use case for copying files, e.g. patching.

1

1 Answer 1

11

Use this to get the environment variable path

var path = Environment.ExpandEnvironmentVariables(value);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.