批处理文件 FOR/f 扩展
我有一个包含目录名称的文件(directories.txt
),每个目录名称都在一行上,我喜欢将
C:\Documents and Settings\%USERNAME%\My Documents
脚本中的行扩展到运行脚本的真实用户名。然而,回显与该行完全相同,并且 %USERNAME%
不会扩展。
FOR /f "tokens=*" %%X IN (directories.txt) DO (
ECHO %%X
)
回声显示“C:\Documents and Settings\%USERNAME%\My Documents”而不是 C:\Documents and Settings\ janco \My Documents
有什么想法吗?
I have a file (directories.txt
) with directory names, each on a single line and I like to expand the line
C:\Documents and Settings\%USERNAME%\My Documents
In my script to the real user name running the script. However the echo comes out exactly the same as the line and %USERNAME%
does not expand.
FOR /f "tokens=*" %%X IN (directories.txt) DO (
ECHO %%X
)
The echo shows "C:\Documents and Settings\%USERNAME%\My Documents" instead of C:\Documents and Settings\ janco \My Documents
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经设法使用变量替换来做到这一点:
I've managed to do this using variable substitution: