批量改进复制检查代码

时间:2018-03-22 15:58:31

标签: performance batch-file for-loop random duplicates

这段代码效果很好!但有没有办法让它更快?目前,它输出正常,但稍有延迟,因为它经常创建和删除文件。最后,我们的目标是让它停止重复,它会做到这一点,但如何才能更有效地完成?

代码:

@echo off

SETLOCAL EnableDelayedExpansion

goto :start

:attackers
set i=0
for %%a in (Vigil Ela Lesion Mira Echo Caviera Valkyrie Frost Mute
            Smoke Castle Pulse Doc Rook Jager Bandit Tachanka Kapkan) do (
   set /A i+=1
   set operator[!i!]=%%a
)
set /a operator=%random%%%i+1
set operator=!operator[%operator%]!
if not exist "ops\" mkdir ops\
if exist ops\%operator%.txt (goto :attackers)
copy /y NUL ops\%operator%.txt >NUL
exit /B

:start
for /l %%x in (1, 1, 5) do (
call :attackers
echo !operator!
)
pause
del /q ops\
goto :start

1 个答案:

答案 0 :(得分:0)

此代码更改在我4岁的I5计算机上即时运行。

@echo off
SETLOCAL EnableDelayedExpansion

set i=0
for %%a in (Vigil Ela Lesion Mira Echo Caviera Valkyrie Frost Mute
            Smoke Castle Pulse Doc Rook Jager Bandit Tachanka Kapkan) do (
   set /A i+=1
   set operator[!i!]=%%a
)

goto :start

:attackers
set /a rand=%random% %% i + 1
set operator=!operator[%rand%]!
IF NOT DEFINED attackers (set "attackers=#%operator%#" &GOTO :EOF)
if "!attackers:#%operator%#=!"=="%attackers%" (
    set "attackers=#%operator%#%attackers%"
) else (
    GOTO attackers
)
exit /B

:start
set "attackers="
for /l %%x in (1, 1, 5) do (
call :attackers
echo !operator!
)
pause
goto :start