批处理文件FOR / F扩张 [英] Batch file FOR/f expansion
本文介绍了批处理文件FOR / F扩张的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件( directories.txt
)与目录的名称,每个名称在一行,我想扩大行
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
在我的脚本运行脚本的真实用户名。然而回声出来完全一样的行和%USERNAME%
不展开。
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
)
回波显示C:\\ Documents和Settings \\%USERNAME%\\我的文档,而不是C:\\ Documents和Settings \\ JANCO \\我的文档
任何想法?
推荐答案
我已经成功地做到这一点使用变量替换:
I've managed to do this using variable substitution:
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "tokens=*" %%X IN (directories.txt) DO (
SET DIR=%%X
ECHO !DIR:%%USERNAME%%=%USERNAME%!
)
这篇关于批处理文件FOR / F扩张的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文