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

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

问题描述

我知道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.

如果你不想测试操作系统版本,你可以简单地检查文档是否存在,如果不存在尝试我的文档,反之亦然。这并不完美,因为s / o可能在他的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.

Btw:我的系统是德文,所以这个文件夹叫做Dokumente。您可能需要考虑到这一点。

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

该文件夹的路径存储在

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders


$ 个人下的b $ b

。您需要注册表访问。

under Personal. You need registry access, though.

资料来源: Microsoft

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

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