批处理脚本创建多个m3u8清单文件(batch script to create multiple m3u8 manifest files)

编程入门 行业动态 更新时间:2024-10-27 14:20:34
批处理脚本创建多个m3u8清单文件(batch script to create multiple m3u8 manifest files)

我试图创建一个批处理脚本来创建多个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 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 /a n=%%x+10 for /L %%n IN (%%x, 1, !n!) do ( @echo #EXTINF:10.00000,>>!file! @echo fileSequence%%n.ts>>!file! ) @echo #EXT-X-ENDLIST>>!file! )

我不确定为什么你在开始时设置回声然后抑制单个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 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 /a n=%%x+10 for /L %%n IN (%%x, 1, !n!) do ( @echo #EXTINF:10.00000,>>!file! @echo fileSequence%%n.ts>>!file! ) @echo #EXT-X-ENDLIST>>!file! )

I'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"

本文发布于:2023-07-23 04:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1227563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   批处理   脚本   清单   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!