本文介绍了我怎样才能获得当前用户目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用这个:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
我得到这样的输出:
I get this output:
"C:\\Documents and Settings\\[USER]\\Application Data"
我如何获得
"C:\\Documents and Settings\\[USER]\\"
推荐答案
可能这将是一个很好的解决方案:以帐户,这是否是VISTA / Win7的或XP,不使用环境变量:
May be this will be a good solution: taking in account whether this is Vista/Win7 or XP and without using environment variables:
string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
if ( Environment.OSVersion.Version.Major >= 6 ) {
path = Directory.GetParent(path).ToString();
}
虽然使用环境变量更加清晰。
Though using the environment variable is much more clear.
这篇关于我怎样才能获得当前用户目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!