我整天都在尝试通过使流程自动化来简化我的工作。这是到目前为止我得到的:
@echo off
setlocal EnableDelayedExpansion
for /l %%x in (1,1,10) do (
set /a counter=%%x+1
set output=%%x
start /wait ffmpeg.exe -i "blabla/playlist.m3u8" -c copy C:\teste\%%x.ts
)
pause >nul
blabla/playlist.m3u8
总是在变化(请参阅下面的文件),我想使用递增的变量重命名流(链接),以便第一个变为1.ts
,第二个2.ts
依次类推。
假设我的文件(streams.txt
)的构造如下:
blabla1/playlist1.m3u8
blabla2/playlist132.m3u8
blabla3/playlist12.m3u8
blabla4/playlist66.m3u8
...
如何解析for
循环中文件的每一行,并通过增加%%x
变量来重命名流?
//我知道下一个语法:for /F "tokens=*" %%A in (myfile.txt) do [process] %%A
但是我不知道如何在我的情况下实际应用它
另一种更简单的方法:
@echo off
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" streams.txt') do (
ECHO start /wait ffmpeg.exe -i "%%b" -c copy C:\teste\%%a.ts
)
该findstr /N
命令将对行进行枚举,因此没有必要为数字使用另一个变量。输出为:
start /wait ffmpeg.exe -i "blabla1/playlist1.m3u8" -c copy C:\teste\1.ts
start /wait ffmpeg.exe -i "blabla2/playlist132.m3u8" -c copy C:\teste\2.ts
start /wait ffmpeg.exe -i "blabla3/playlist12.m3u8" -c copy C:\teste\3.ts
start /wait ffmpeg.exe -i "blabla4/playlist66.m3u8" -c copy C:\teste\4.ts
编辑:新方法添加为回复评论
@echo off
setlocal EnableDelayedExpansion
< anotherFile.txt (
for /F "delims=" %%a in (streams.txt) do (
set /P "line="
ECHO start /wait ffmpeg.exe -i "%%a" -c copy "C:\teste\!line!.ts"
)
)
输出:
start /wait ffmpeg.exe -i "blabla1/playlist1.m3u8" -c copy "C:\teste\first-line-of another-file.ts"
start /wait ffmpeg.exe -i "blabla2/playlist132.m3u8" -c copy "C:\teste\second-line-of another-file.ts"
start /wait ffmpeg.exe -i "blabla3/playlist12.m3u8" -c copy "C:\teste\third-line-of another-file.ts"
start /wait ffmpeg.exe -i "blabla4/playlist66.m3u8" -c copy "C:\teste\fourth-line-of another-file.ts"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句