批量复制.txt文件名列表并生成另一个.txt

时间:2016-03-13 15:27:06

标签: windows batch-file

我从这个例子开始:我有一个名为concatlist.txt的文件,其中包含一个真实的.mxf文件列表,例如

CONCATLIST.TXT

c:\myfolder\C0060.MXF 
c:\myfolder\C0061.MXF 
c:\myfolder\C0062.MXF 
c:\myfolder\C0063.MXF 
c:\myfolder\C0064.MXF
c:\myfolder\C0065.MXF 
c:\myfolder\C0066.MXF 
c:\myfolder\C0067.MXF 
c:\myfolder\C0068.MXF 
c:\myfolder\C0069.MXF 
c:\myfolder\C0070.MXF 
c:\myfolder\C0071.MXF 
c:\myfolder\C0072.MXF 
c:\myfolder\C0060.MXF 
c:\myfolder\C0061.MXF 
c:\myfolder\C0062.MXF 
c:\myfolder\C0063.MXF 
c:\myfolder\C0064.MXF 
c:\myfolder\C0065.MXF 
c:\myfolder\C0066.MXF 
c:\myfolder\C0067.MXF 
c:\myfolder\C0068.MXF 
c:\myfolder\C0069.MXF 
c:\myfolder\C0070.MXF 
c:\myfolder\C0071.MXF 
c:\myfolder\C0072.MXF

我想创建一个批处理脚本,从concatlist.txt创建一个target.txt,每个filename_and_pathfile都像这个.txt文件一样被放置:

SetMemoryMax(16)
LoadPlugin("v:\automazioneclip\avisynth\plugins\LSMASHSource.dll")

videofile0 = LWLibavVideoSource("c:\myfolder\C0060.MXF")
audiofile0 = LWLibavAudioSource("c:\myfolder\C0060.MXF")
file0 = audiodub(videofile0,audiofile0)

videofile1 = LWLibavVideoSource("c:\myfolder\C0061.MXF")
audiofile1 = LWLibavAudioSource("c:\myfolder\C0061.MXF")
file1 = audiodub(videofile1,audiofile1)

videofile2 = LWLibavVideoSource("c:\myfolder\C0062.MXF")
audiofile2 = LWLibavAudioSource("c:\myfolder\C0062.MXF")
file2 = audiodub(videofile2,audiofile2)

videofile3 = LWLibavVideoSource("c:\myfolder\C0063.MXF")
audiofile3 = LWLibavAudioSource("c:\myfolder\C0063.MXF")
file3 = audiodub(videofile3,audiofile3)

videofile4 = LWLibavVideoSource("c:\myfolder\C0064.MXF")
audiofile4 = LWLibavAudioSource("c:\myfolder\C0064.MXF")
file4 = audiodub(videofile4,audiofile4)

videofile5 = LWLibavVideoSource("c:\myfolder\C0065.MXF")
audiofile5 = LWLibavAudioSource("c:\myfolder\C0065.MXF")
file5 = audiodub(videofile5,audiofile5)

videofile6 = LWLibavVideoSource("c:\myfolder\C0066.MXF")
audiofile6 = LWLibavAudioSource("c:\myfolder\C0066.MXF")
file6 = audiodub(videofile6,audiofile6)

videofile7 = LWLibavVideoSource("c:\myfolder\C0067.MXF")
audiofile7 = LWLibavAudioSource("c:\myfolder\C0067.MXF")
file7 = audiodub(videofile7,audiofile7)

videofile8 = LWLibavVideoSource("c:\myfolder\C0068.MXF")
audiofile8 = LWLibavAudioSource("c:\myfolder\C0068.MXF")
file8 = audiodub(videofile8,audiofile8)

videofile9 = LWLibavVideoSource("c:\myfolder\C0069.MXF")
audiofile9 = LWLibavAudioSource("c:\myfolder\C0069.MXF")
file9 = audiodub(videofile9,audiofile9)

videofile10 = LWLibavVideoSource("c:\myfolder\C0070.MXF")
audiofile10 = LWLibavAudioSource("c:\myfolder\C0070.MXF")
file10 = audiodub(videofile10,audiofile10)

videofile11 = LWLibavVideoSource("c:\myfolder\C0071.MXF")
audiofile11 = LWLibavAudioSource("c:\myfolder\C0071.MXF")
file11 = audiodub(videofile11,audiofile11)

videofile12 = LWLibavVideoSource("c:\myfolder\C0072.MXF")
audiofile12 = LWLibavAudioSource("c:\myfolder\C0072.MXF")
file12 = audiodub(videofile12,audiofile12)    
file0++file1++file2++file3++file4++file5++file6++file7++file8++file9++file10++file11++file12

另一个例子:

假设concatList.txt是这个

c:\cats\catsVideoA.MXF
c:\dogs\dogsVideoB.MXF

批处理应生成此target.txt:

SetMemoryMax(16)
LoadPlugin("v:\automazioneclip\avisynth\plugins\LSMASHSource.dll")

videofile0 = LWLibavVideoSource("c:\cats\catsVideoA.MXF")
audiofile0 = LWLibavAudioSource("c:\cats\catsVideoA.MXF")
file0 = audiodub(videofile0,audiofile0)

videofile1 = LWLibavVideoSource("c:\dogs\dogsVideoB.MXF")
audiofile1 = LWLibavAudioSource("c:\dogs\dogsVideoB.MXF")
file1 = audiodub(videofile1,audiofile1)
file0++file1

2 个答案:

答案 0 :(得分:1)

测试此代码:

@echo off
setlocal enabledelayedexpansion
set num=0
(
echo SetMemoryMax(16^)
echo LoadPlugin("v:\automazioneclip\avisynth\plugins\LSMASHSource.dll"^)

for /f "usebackq delims=" %%a in ("CONCATLIST.TXT") do (
echo(
set line=!line!++file!num!
echo videofile!num! = LWLibavVideoSource("%%a"^)
echo audiofile!num! = LWLibavAudioSource("%%a"^)
echo file!num! = audiodub(videofile!num!,audiofile!num!^)
set /a num+=1
)
echo !line:~2!
)>"target.txt"

答案 1 :(得分:0)

这是一个可以支持"无限制" concatlist大小。 (不是真的无限,但比实际的数字要大得多)

我还避免延迟扩展,因此!不会导致文件路径出现任何问题。

@echo off
setlocal disableDelayedExpansion
call :createFile >target.txt
exit /b

:createFile
echo SetMemoryMax(16)
echo LoadPlugin("v:\automazioneclip\avisynth\plugins\LSMASHSource.dll")

for /f "tokens=1* delims=:" %%A in ('findstr /n "^" "concatlist.txt"') do (
  echo(
  echo videofile%%A = LWLibavVideoSource("%%B"^)
  echo audiofile%%A = LWLibavAudioSource("%%B"^)
  echo file%%A = audiodub(videofile%%A,audiofile%%A^)
  set "cnt=%%A"
)

set /a cnt2=cnt-1
for /l %%N in (1 1 %cnt2%) do <nul set /p "=file%%N++"
echo file%cnt%

exit /b

修改

如果您确实坚持编号从0开始而不是1,那么最好还是使用SET / A来跟踪计数。

@echo off
setlocal disableDelayedExpansion
call :createFile >target.txt
type target.txt
exit /b

:createFile
echo SetMemoryMax(16)
echo LoadPlugin("v:\automazioneclip\avisynth\plugins\LSMASHSource.dll")

set /a cnt=0
for /f "usebackq eol=: delims=" %%A in ("concatlist.txt") do (
  echo(
  setlocal enableDelayedExpansion
  for %%N in (!cnt!) do (
    endlocal
    echo videofile%%N = LWLibavVideoSource("%%A"^)
    echo audiofile%%N = LWLibavAudioSource("%%A"^)
    echo file%%N = audiodub(videofile%%N,audiofile%%N^)
  )
  set /a cnt+=1
)

<nul set /p "=file0"
for /l %%N in (1 1 %cnt%) do <nul set /p "=++file%%N"
echo(

exit /b