我试图写一些简单的脚本,但我无法弄清楚。
基本上,一个用户被问到问题1:“他们想要添加多less(在这种情况下)video文件来创build一个大的video文件?
然后用户被问到问题2:“你想添加的文件的名字是什么? 现在这是我遇到的问题…
如何创build一个for循环,询问问题2在第一个问题中给出的次数,并将每个答案保存为一个唯一variables(我猜测是在variables的递减处)
从用户获得所有正确的文件名后,程序将根据video程序语法调用video程序(THAT语法我不需要帮助,我理解这一部分)
恩。 (“?”意思是我不知道该放什么)
@echoclosures
set / p howmany =你想添加多less个文件?
为/? %%variables(???)in(%howmany%???)do(set / p inputfilename =要添加的第一个文件的名称是什么?inputfilename = filename set%howmany%-1 ??? = %多less%????)
所以如果用户对问题1回答5,则for循环应该问问题5五次,每次给出答案时创build5个唯一variables。 inputfilename1 = movie1.mov inputfilename2 = movie2.mov等。
我一直试图弄清楚这几天..我不能说唱我的头。 我以前做过很多的命令,但是这让我难住了。 我的浏览器历史充满了谷歌search,似乎有人会问任何types的文件。 如果我在这个问题上发现了任何东西,它总是被要求使用不同的编程语言。 我的大脑被炸。 这甚至有可能吗? 请提前帮助和感谢。
虽然马丁的答案描述了如何创造独特的变量,但他没有解释如何阅读它们。 当你在说“把每个答案保存为一个唯一的变量”时,这里涉及的概念就是ARRAY 。 您需要使用Delayed Expansion来获取唯一变量(“数组元素”)的值; 有关更多详细信息,请键入set /?
并寻找“延期扩张”。 您可以在此文章中阅读有关批处理文件中阵列管理的详细说明: 数组,cmd.exe(批处理)脚本中的数组,链接列表和其他数据结构
@echo off setlocal EnableDelayedExpansion set /p howmany=How many files do you want to add? for /L %%i in (1,1,%howmany%) do ( set /p inputfilename[%%i]=what is the name of the file you want to add? ) rem Process array elements (just show them in this case) for /L %%i in (1,1,%howmany%) do ( echo %%i- !inputfilename[%%i]! )
下面的示例可以帮助您更轻松地理解数组管理:
@echo off setlocal EnableDelayedExpansion rem Create an array of ordinal terms set i=0 for %%a in (first second third fourth fifth sixth) do ( set /A i+=1 set term[!i!]=%%a ) rem Previous FOR is equivalent to: set term[1]=first, set term[2]=second, ... set /p howmany=How many files do you want to add? for /L %%i in (1,1,%howmany%) do ( set /p inputfilename[%%i]=what is the name of the !term[%%i]! file you want to add? ) rem Process array elements (just show them in this case) for /L %%i in (1,1,%howmany%) do ( echo The !term[%%i]! file is !inputfilename[%%i]! )
无论如何回答你的实际问题:
@echo off set /p howmany=How many files do you want to add? for /L %%i in (1, 1, %howmany%) do ( set /p inputfilename%%i=what is the name of the first file you want to add? ) rem Output the variables to check set inputfilename
输出:
How many files do you want to add? 3 what is the name of the first file you want to add? first what is the name of the first file you want to add? second what is the name of the first file you want to add? third inputfilename1=first inputfilename2=second inputfilename3=third
你需要这些N个变量吗? 我猜你需要传递一些文件名到一些脚本/命令行应用程序。
那么,用(空格? – )分隔的文件名列表来处理一个变量是不是更好?
喜欢:
@echo off set /p howmany=How many files do you want to add? set list= :NEXT if %howmany% leq 0 goto END set /p inputfilename=what is the name of the first file you want to add? set list=%list% "%inputfilename%" set /a howmany=%howmany% - 1 goto NEXT :END echo %list%