Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以在%USERPROFILE%cmd 中或通过 bat 文件获取用户的主目录。但我只得到一个反斜杠C:\Users\guy,我需要用转义斜杠对其进行转换。
%USERPROFILE%
C:\Users\guy
它应该看起来像C:\\Users\\guy
C:\\Users\\guy
这该怎么做?
试试这个:
@echo off set "profile=%USERPROFILE:\=\\%" echo %profile%
这适用于我的机器:
echo %USERPROFILE:\=\\%
或作为变量:
set a=%USERPROFILE:\=\\% echo %a%