在文件路径中使用环境变量 [英] Using environment variable in a file path
问题描述
我有一个环境变量设置指向一个特定的文件夹(称之为MyFolder文件为例)。在%MyFolder文件%\\子文件夹
键入Windows资源管理器出现的子文件夹。然而,当我通过 SelectedPath = @%MyFolder文件%\\子文件夹;
到的FolderBrowserDialog
,它不的工作。
I've got an environment variable set that points to a specific folder (call it MYFOLDER for example). When typing in %MYFOLDER%\SubFolder
into windows explorer the subfolder appears. However, when I pass SelectedPath = @"%MYFOLDER%\SubFolder";
to a FolderBrowserDialog
, it doesn't work.
我试着用 Path.GetFullPath(..)
,但这似乎返回可执行文件的bin文件夹(而在VS调试)与上MyFolder的%%最后,而不是路径,我期望。
I tried using Path.GetFullPath(..)
, but this seems to return the bin folder of the executable (while debugging in VS) with %MYFOLDER% on the end, instead of the path I'd expect.
任何人都知道如何得到它的正确使用环境变量?
Anyone know how to get it to use the environment variable properly?
推荐答案
展开它首先:
string path = Environment.ExpandEnvironmentVariables(value);
<一个href=\"http://msdn.microsoft.com/en-us/library/system.environment.expandenvironmentvariables.aspx\">http://msdn.microsoft.com/en-us/library/system.environment.expandenvironmentvariables.aspx
这篇关于在文件路径中使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!