问题在于,程序计算要复制和复制的文件数量的部分不起作用。在我的测试中,%levelcount%为4,在某些时候它只复制了文件level_4.lvl。
这是config.ini:
mapname=maze
mode=123
metadata=a brief description
sound=
config=
levelcount=4
批处理脚本:
@echo off
setlocal EnableDelayedExpansion EnableExtensions
::Thanks to reddit.com/u/Danoodle
:: The source file to parse.
set "infile=%~1"
if not defined infile set /p "infile=Source file>"
:: Default output filename. Set blank to discard anything prior to the first #.
set "outfile="
:: Extension to use for output files. Set blank if the extension is given by the # line.
set "outext=%~x1"
:: Here begins the program.
rem %%@ is the line number (1,2,...); %%A is the line contents.
for /f "tokens=1* delims=:" %%@ in ('findstr /n "^^" "!infile!"') do (
set "line=%%A"
if "!line:~0,1!" == "#" (
set "outfile=!line:~1!!outext!"
) else if defined outfile (
1>> "!outfile!" echo/!line!
)
)
endlocal
if exist "animation.txt" copy /a "animation.txt" "animation" & del animation.txt
if exist "config.txt" copy /a "config.txt" "config.ini" & del config.txt
if exist "autorun.txt" copy /a "autorun.txt" "autorun.bat" & del autorun.txt
mkdir levels
for /f "delims=" %%A in (config.ini) do set "%%A"
:copylevel
copy "level_%levelcount%.txt" "levels\level_%levelcount%.lvl
del /q "level_%levelcount%.txt"
if "%levelcount%==1" goto end
set /a "levelcount=%levelcount%-1"
goto copylevel
:end
exit /b
答案 0 :(得分:1)
我认为从:copylevel
替换为以下内容:
for /L %%I in (%levelcount%,-1,1) do (
if exist "level_%%I.txt" (
>NUL move /y "level_%%I.txt" "levels\level_%%I.lvl"
)
)
for /L
循环应该比goto
循环快,并且您不必担心通过%levelcount%
递减set /a
。
至于导致上述脚本中断的原因,我认为它是if "%levelcount%==1" goto end
行。您必须单独引用每个参数,而不是两者都引用。它应该是if "%levelcount%"=="1"
或if %levelcount% equ 1
。