Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use environment variables in Path.Combine()?

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.

like image 494
Doug Avatar asked Oct 07 '14 04:10

Doug


People also ask

Can I use variables in .env file?

You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of your Compose file). Values set in the shell environment override those set in the .env file.

Which environment variable is used to set the PATH?

The PATH environment variable is an important security control. It specifies the directories to be searched to find a command. The default systemwide PATH value is specified in the /etc/profile file, and each user normally has a PATH value in the user's $HOME/.

What does PATH combine do in C#?

Combines two strings into a path.


1 Answers

Use this to get the environment variable path

var path = Environment.ExpandEnvironmentVariables(value);
like image 69
failedprogramming Avatar answered Sep 20 '22 02:09

failedprogramming