我试图创建一个批处理脚本来创建多个m3u8清单文件。 这是我试图做的一些伪代码
for (int i= 0; i < numberOfFiles; i++) { write preset lines to file. for (int x = i x < i+10; x++) { write string + x in line to file } write end of file line to file }这就是我到目前为止所拥有的。 我有内部for循环的问题。 我如何让它从x运行到x + 10?
@echo on setlocal enabledelayedexpansion set x=0 for /L %%x IN (0,1,5) do ( set file="index%%x.m3u8" @echo #EXTM3U>>!file! @echo #EXT-X-TARGETDURATION:10>>!file! @echo #EXT-X-VERSION:3>>!file! @echo #EXT-X-MEDIA-SEQUENCE:0>>!file! @echo #EXT-X-PLAYLIST-TYPE:VOD>>!file! set n=%x% for /L %%n IN (n, 1, %x%+10) do ( @echo #EXTINF:10.00000,>>!file! @echo fileSequence!n!.ts>>!file! ) @echo #EXT-X-ENDLIST>>!file! )im trying to create a batch script to create multiple m3u8 manifest files. here is some pseudo code for what im trying to do
for (int i= 0; i < numberOfFiles; i++) { write preset lines to file. for (int x = i x < i+10; x++) { write string + x in line to file } write end of file line to file }this is what i have so far. i am having issues with the inner for loop. how can i make it run from x to x + 10?
@echo on setlocal enabledelayedexpansion set x=0 for /L %%x IN (0,1,5) do ( set file="index%%x.m3u8" @echo #EXTM3U>>!file! @echo #EXT-X-TARGETDURATION:10>>!file! @echo #EXT-X-VERSION:3>>!file! @echo #EXT-X-MEDIA-SEQUENCE:0>>!file! @echo #EXT-X-PLAYLIST-TYPE:VOD>>!file! set n=%x% for /L %%n IN (n, 1, %x%+10) do ( @echo #EXTINF:10.00000,>>!file! @echo fileSequence!n!.ts>>!file! ) @echo #EXT-X-ENDLIST>>!file! )最满意答案
您似乎将环境变量与循环变量混淆。 这两者彼此无关。
尝试对脚本进行以下修改:
@echo on setlocal enabledelayedexpansion我不确定为什么你在开始时设置回声然后抑制单个echo s,但你可以通过将抑制和重定向应用于块而不是单独的命令来简化脚本。 特别是,主循环中的一系列echo可以像这样重写:
@( echo #EXTM3U echo #EXT-X-TARGETDURATION:10 echo #EXT-X-VERSION:3 echo #EXT-X-MEDIA-SEQUENCE:0 echo #EXT-X-PLAYLIST-TYPE:VOD )>>!file!内环的echo可以以类似的方式转换为块。 当然,块内的缩进是可选的。
You seem to be confusing environment variables with loop variables. The two have nothing to do with each other.
Try the following modification of your script:
@echo on setlocal enabledelayedexpansionI'm not sure why you are setting the echo on at the beginning and then suppressing individual echos, but you could simplify the script a bit by applying both the suppression and the redirection to blocks instead of individual commands. In particular, the series of echos in the main loop could be rewritten like this:
@( echo #EXTM3U echo #EXT-X-TARGETDURATION:10 echo #EXT-X-VERSION:3 echo #EXT-X-MEDIA-SEQUENCE:0 echo #EXT-X-PLAYLIST-TYPE:VOD )>>!file!The inner loop's echos could be transformed into a block in a similar fashion. The indentation inside the block is optional, of course.
更多推荐
file,@echo,电脑培训,计算机培训,IT培训"/> <meta name="description"
发布评论