简体   繁体   中英

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, eg patching.

使用它来获取环境变量路径

var path = Environment.ExpandEnvironmentVariables(value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM