如何使用批处理文件创建文件

时间:2016-06-13 20:37:29

标签: batch-file

我想使用批处理脚本编写新文件。我想让bat提示我输入文件名,我想我有“set / P file =输入文件名:”然后将该名称放入文件名,并在文件名中放置相同名称5个并将文件保存为该文件name.smil 看看我有什么,我知道这是不对的,但希望你能看到我想要做的事情。

set / P file =输入文件名:

<?xml version="1.0" encoding="UTF-8"?>
<smil title="%file%">
<body>
    <switch>
        <video height="1080" src="%file%-1080.mp4"
        systemLanguage="eng" width="1920">
            <param name="videoBitrate" value="5000000" valuetype="data"></param>
            <param name="audioBitrate" value="320000" valuetype="data"></param>
        </video>
        <video height="720" src="%file%-720.mp4"
        systemLanguage="eng" width="1280">
            <param name="videoBitrate" value="3000000" valuetype="data"></param>
            <param name="audioBitrate" value="192000" valuetype="data"></param>
        </video>
        <video height="540" src="%file%-540.mp4"
        systemLanguage="eng" width="960">
            <param name="videoBitrate" value="1500000" valuetype="data"></param>
            <param name="audioBitrate" value="128000" valuetype="data"></param>
        </video>
        <video height="360" src="%file%-360.mp4"
        systemLanguage="eng" width="640">
            <param name="videoBitrate" value="750000" valuetype="data"></param>
            <param name="audioBitrate" value="96000" valuetype="data"></param>
        </video>
    </switch>
</body>
</smil>

4 个答案:

答案 0 :(得分:0)

我无法弄清楚如何让它与多行xml一起使用,所以我以这个怪物结束了:

@echo off

set /p name=Enter File Name:

set file=C:\Temp\%name%.smil

echo ^<?xml version=^"1.0^" encoding=^"UTF-8^"?^> > %file%
echo ^<smil title=^"%name%^"^> >> %file%
echo ^<body^> >> %file%
echo     ^<switch^> >> %file%
echo         ^<video height=^"1080^" src=^"%name%-1080.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"1920^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"5000000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"320000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo         ^<video height=^"720^" src=^"%name%-720.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"1280^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"3000000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"192000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo         ^<video height=^"540^" src=^"%name%-540.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"960^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"1500000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"128000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo         ^<video height=^"360^" src=^"%name%-360.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"640^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"750000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"96000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo     ^</switch^> >> %file%
echo ^</body^> >> %file%
echo ^</smil^> >> %file%

pause

答案 1 :(得分:0)

仍然有问题,让所有人一次运行,

set /P file=Enter input File Name:
set /P fileext=Enter input File Extension: 

handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-1080.mp4" -w 1920 --preset="Normal" -E av_aac -B 320 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-720.mp4" -w 1280 --preset="Normal" -E av_aac -B 192 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-540.mp4" -w 960 --preset="Normal" -E av_aac -B 128 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-360.mp4" -w 640 --preset="Normal" -E av_aac -B 96 -6 stereo

@echo off

set path=\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%.smil

echo ^<?xml version=^"1.0^" encoding=^"UTF-8^"?^> > %path%
echo ^<smil title=^"%file%^"^> >> %path%
echo ^<body^> >> %path%
echo     ^<switch^> >> %path%
echo         ^<video height=^"1080^" src=^"%file%-1080.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1920^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"5000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"320000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"720^" src=^"%file%-720.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1280^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"3000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"192000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"540^" src=^"%file%-540.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"960^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"1500000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"128000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"360^" src=^"%file%-360.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"640^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"750000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"96000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo     ^</switch^> >> %path%
echo ^</body^> >> %path%
echo ^</smil^> >> %path%

exit

答案 2 :(得分:0)

这就是我最终得到的结果,感谢您的帮助。

set /P file=Enter input File Name:
set /P fileext=Enter input File Extension: 

handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-1080.mp4" -w 1920 --preset="Normal" -E av_aac -B 320 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-720.mp4" -w 1280 --preset="Normal" -E av_aac -B 192 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-540.mp4" -w 960 --preset="Normal" -E av_aac -B 128 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-360.mp4" -w 640 --preset="Normal" -E av_aac -B 96 -6 stereo

set path="\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%.smil"

@echo off

echo ^<?xml version=^"1.0^" encoding=^"UTF-8^"?^> > %path%
echo ^<smil title=^"%file%^"^> >> %path%
echo ^<body^> >> %path%
echo     ^<switch^> >> %path%
echo         ^<video height=^"1080^" src=^"%file%-1080.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1920^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"5000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"320000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"720^" src=^"%file%-720.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1280^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"3000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"192000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"540^" src=^"%file%-540.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"960^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"1500000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"128000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"360^" src=^"%file%-360.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"640^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"750000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"96000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo     ^</switch^> >> %path%
echo ^</body^> >> %path%
echo ^</smil^> >> %path%

exit

答案 3 :(得分:0)

说到%path $。

有没有办法将此路径添加到具有设置路径的所有路径。 现在路径在5个地方。如果我可以在一个地方改变并让它在所有5个地方都有效?

\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\