Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理集/a和副本_Batch File - Fatal编程技术网

Batch file 批处理集/a和副本

Batch file 批处理集/a和副本,batch-file,Batch File,这里的问题是,程序计算要复制的文件数量并进行复制的部分不起作用。在我的测试中%levelcount%是4,在某个点上它只复制了文件级别_4.lvl 下面是config.ini: mapname=maze mode=123 metadata=a brief description sound= config= levelcount=4 批处理脚本: @echo off setlocal EnableDelayedExpansion EnableExtensions ::Thanks to re

这里的问题是,程序计算要复制的文件数量并进行复制的部分不起作用。在我的测试中%levelcount%是4,在某个点上它只复制了文件级别_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

我认为从
: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
循环快,而且您不必担心通过
set/A
减少
%levelcount%


至于是什么导致上面的脚本中断,我认为这是
如果“%levelcount%==1”转到结束
行。您必须单独引用每个参数,而不是同时引用两个参数。它应该是
如果“%levelcount%”如果“%1”
或者
如果%levelcount%eq 1

以及rojo所说的,在这个if语句
如果“!line:~0,1!”==”。(
批处理比较中的if语句
如果“!line:~0,1!”=“。”(