【问题标题】:How do I make a dynamic config maker? batch如何制作动态配置生成器?批
【发布时间】:2013-10-31 15:48:02
【问题描述】:

我正在尝试制作一个批处理脚本,为指定文件夹中的每个文件创建一个配置文件。

创建配置文件后,它会执行一个程序,该程序使用选定的配置文件,然后转换配置中的指定文件。

这是我当前的代码:

    :start
@echo off
cls
cd /d %~dp0
goto source

rem This sets up the working folder. I usually do this because I need to but I am 
rem not sure about it this time...

:source
echo Please select the folder with the ARF files in it.
set /p source=E.G. C:\Users\Elliot\Desktop\toconvert:
goto dest


rem This sets the folder location for the ARF files.
rem I am going to add a menu for simplicity sake later.


:dest
echo Please select where the mp4 files should appear.
set /p dest=E.G. C:\Users\Elliot\Desktop\Converted:
goto cfgname


rem This sets the output folder for the converted files.
rem Again I will make a menu in the future.


:cfgname


goto createcfg

rem this sets the name of the CFG that will be created for the ARF file


:createcfg
echo [Console] >> %MP4%.cfg
echo inputfile=%source%\1.arf >> MP4.cfg
echo media=MP4 >> MP4.cfg
echo showui=1 >> MP4.cfg
echo [UI] >> MP4.cfg
echo chat=1 >> MP4.cfg
echo qa=0 >> MP4.cfg
echo largeroutline=1 >> MP4.cfg
echo [MP4] >> MP4.cfg
echo outputfile=%dest%\1.mp4 >> MP4.cfg
echo width=1024 >> MP4.cfg
echo height=768 >> MP4.cfg
echo framerate=10 >> MP4.cfg


rem This makes the config file that is required by the player to convert

:convert
cd C:\programdata\webex\webex\500
nbrplay.exe -Convert "%cfg%"

:end
echo Thanks for using Elliot Labs Auto Converter.
echo for feature requests please email: elliot-labs@live.com
pause | echo Press any key to exit...
exit

:preloop
set num=0
goto loop

:loop
cls
echo %num%
pause
set /a num+=1
if %num%==6 (goto end) ELSE goto loop

这仅适用于一个文件。如何使它适用于整个文件夹。

【问题讨论】:

  • 这不是批处理脚本。我假设您在每行前面都有一个ECHO 命令?还有,%MP4% 是从哪里来的?
  • 您需要使用 for 循环。请参阅FOR /? 了解更多信息。
  • 我真正想做的就是为指定文件夹中的每个文件创建一个配置文件。完成配置后,它会在每个配置上执行一个程序(nbrplay -Convert %configfile%)。我有编码器阻塞。是的,它在每个命令前面都有回声。我还没有制作 %MP4% 但它象征着该配置可以用于不同的 ARF 文件。

标签: windows shell batch-file dynamic


【解决方案1】:
@echo off &setlocal
for %%a in ("%cd%\*.arf") do call:MakeCFG "%%~a"
goto:eof

:MakeCFG
setlocal
set "MP4=%~n1"
set "source=%~dp1"
set "filename=%~n1"
set "dest=X:\destination"

(
ECHO([Console]
ECHO(inputfile=%source%%filename%
ECHO(media=MP4
ECHO(showui=1
ECHO([UI]
ECHO(chat=1
ECHO(qa=0
ECHO(largeroutline=1
ECHO([MP4]
ECHO(outputfile=%dest%\%filename%.mp4
ECHO(width=1024
ECHO(height=768
ECHO(framerate=10
)>"%MP4%.cfg"
exit /b 0

【讨论】:

  • +1 使用set "filename_ext=%~nx1" 如果在配置文件中需要实际文件名,如您的示例代码所示。您可以在exit /b 0 所在的位置添加转换器命令行。
  • 谢谢!我将使用此代码并尝试弄清楚它的作用。它很好用,除了以下行: ECHO(inputfile=%source%%filename% 我不得不将它更改为: ECHO(inputfile=%source%%filename%.arf 让转换器找到特定的 ARF 文件。再次感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-06
  • 2012-07-07
相关资源
最近更新 更多