文档目录是否有系统定义的环境变量? [英] Is There A System Defined Environment Variable For Documents Directory?

查看:31
本文介绍了文档目录是否有系统定义的环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Windows XP(以及 Vista 和 Windows 7)上的 %USERPROFILE% 系统定义的环境变量.是否有系统定义的环境变量指向我的文档"目录的位置?默认情况下,在 XP 上它是 %USERPROFILE%My Documents,在 Win 7 上它是 %USERPROFILE%Documents.如果可以的话,我只是想避免在 Powershell 脚本中测试操作系统版本.

I know about the %USERPROFILE% system defined environment variable on Windows XP (and Vista and Windows 7). Is there a system defined environment variable pointing to the location of the "My Documents" directory? On XP by default it's %USERPROFILE%My Documents and on Win 7 it's %USERPROFILE%Documents. I just wanted to avoid having to test for the OS version in a Powershell script if I can avoid it.

推荐答案

在我默认安装的 XP 系统上,没有环境变量.您可以在命令行中使用set"命令(无参数)列出所有变量.所以可能你必须做一个测试.

On my default-installation XP system, there is no environment variable for that. You can list all variables with the "set" command ( no parameters ) in the command line. So probably you have to do a test.

如果您不想测试操作系统版本,您可以简单地检查文档"是否存在,如果不存在,请尝试我的文档",反之亦然.然而,这并不完美,因为他的 XP 机器上可能有一个文档"文件夹.

If you don't want to test for the OS version, you can simply check whether "Documents" exists and if not then try "My Documents" or vice versa. This isn't perfect however, because s/o could have a "Documents" folder on his XP machine.

顺便说一句:我的系统是德国的,所以文件夹被称为Dokumente".您可能需要考虑到这一点.

Btw: my system is German, so the folder is called "Dokumente". You might need to take that into account.

该文件夹的路径存储在

HKEY_CURRENT_USERSOFTWAREMicrosoftWindowsCurrentVersionExplorerUser Shell Folders

个人下.不过,您需要访问注册表.

under Personal. You need registry access, though.

来源:微软

这篇关于文档目录是否有系统定义的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆