I m m 正在处理一个批量文件, 该批量文件生成一个文本文件, 其格式为
Name1
Name2
Name3
etc...
我想做的是创建一个菜单,从文本文件中拉动条目来创建选项。
苏
Menu
1 Name1
2 Name2
etc...
我同意自己创建菜单本身,但它会从文档中获取数据, 并被分配到让我难以接受的变量。 我看过命令, 但我猜我的大脑只是没有环绕着它。 有人知道上面的代码吗?
如有任何协助,将不胜感激。
I m m 正在处理一个批量文件, 该批量文件生成一个文本文件, 其格式为
Name1
Name2
Name3
etc...
我想做的是创建一个菜单,从文本文件中拉动条目来创建选项。
苏
Menu
1 Name1
2 Name2
etc...
我同意自己创建菜单本身,但它会从文档中获取数据, 并被分配到让我难以接受的变量。 我看过命令, 但我猜我的大脑只是没有环绕着它。 有人知道上面的代码吗?
如有任何协助,将不胜感激。
@echo off
setlocal EnableDelayedExpansion
echo Menu
set i=0
for /F "delims=" %%a in (theTextFile.txt) do (
set /A i+=1
set "name[!i!]=%%a"
echo !i! %%a
)
set lastOpt=%i%
:getOption
set /P "opt=Enter desired option: "
if %opt% gtr %lastOpt% (
echo Invalid option
goto getOption
)
echo Process !name[%opt%]!
如果您在循环中逐行生成文本文件行, 您可以在循环中添加以下对应词 :
…
SET /A cnt+=1
…
然后在另一个循环中使用它, 以编号列表的形式输出行的循环 :
…
<YourFile.txt (
FOR /L %%L IN (1,1,%cnt%) DO (
SET /P line=
SETLOCAL EnableDelayedExpansion
ECHO %%L !line!
ENDLOCAL
)
)
但是,如果您的文本文件是作为单一命令(或数个命令)的输出生成的,您可以在此之后计算行数 :
…
FOR /F %%C IN ( FIND /C /V "" ^<YourFile.txt ) DO SET cnt=%%C
…
然后您可以使用上面同样的 FOR/L
环来显示菜单。
I m trying to do some batch replacement for/with a fairly complex pattern So far I find the pattern as: find ( -name *.php -o -name *.html ) -exec grep -i -n hello {} + The string I want ...
I am trying to retrieve the environment variable to detect whether the system is 32 or 64 bit. But on 64 bit server the environment variable %processor_architecture% is returning x86 instead of AMD64. ...
IF %processor_architecture% == AMD64 (SET querypath=hklmsoftwarex) ELSE (SET dsetquerypath=hklmsoftwarey) FOR /F "tokens=* delims=" %%G IN ( REG QUERY "%querypath%" 2^>NUL ) DO ECHO %%G Let ...
I have a batch script that takes arguments from the command line. One of the arguments has a * in it. In spite of putting the argument in quotes, the * gets expanded before the argument gets used in ...
Suppose I have a string "AAA BBB CCC DDD EEE FFF". How can I split the string and retrieve the nth substring, in a batch file? The equivalent in C# would be "AAA BBB CCC DDD EEE FFF".Split()[n]
Binary files have a version embedded in them - easy to display in Windows Explorer. How can I retrieve that file version, from a batch file?
How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....
I don t know how to describe exactly what I m trying to do but here s an example batch file that demonstrates what I can t figure out.: I ve got a batch file. Inside that batch file I m trying to ...