如何创建根据 windows 用户更改的动态本地文件路径

How to create a dynamic local file path that changes based on the windows user

我创建了一个基于用户的动态本地 windows 文件路径。

C:\Users\%USERPROFILE%\rest_of_filepath

此路径在我的本地计算机上运行完美,但当我通过电子邮件将其发送给其他人时,他们收到此错误:

We can't find 'C:\Users\%USERPROFILE%\rest_of_path'. Please make sure you are suing the correct location or web address.

如何让它为我要发送给的其他人工作?

USERPROFILE 是用于检索 Windows 用户配置文件文件夹路径的正确环境变量。即使文件夹位于“non-default”位置,这也能正常工作。 Windows 为此确切原因创建了此环境变量。在 % 中包含一个词会通知 Windows % 中的词是一个环境变量。 Windows 因此知道用与该变量关联的路径替换整个“%USERPROFILE%”。

在问题的情况下,使用路径 C:\Users\%USERPROFILE%\rest_of_filepath。此路径的 C:\Users\ 部分是不必要的,结果为 C:\Users\C:\Users\<userprofilefolder>\rest_of_path,因为环境变量也将检索路径的该部分。

%USERPROFILE\rest_of_path 就够了。

最终,即使电子邮件客户端中的 HTML 解释器能够解析环境变量,出于安全原因,也不允许从电子邮件访问本地系统文件。

建议通过电子邮件发送路径并指示收件人将其复制并粘贴到 Windows 文件资源管理器中 work-around。

来源:Recognized Environment Variables that are recognized only in the user context