您好我想要两个批处理脚本并将它们合并为“一个”。我还希望现在的“One”批处理文件按降序运行。
我可以使用CALL
功能,然后我有三个批处理文件。
我正在尝试将它们组合起来并获得与我在callbatchA + batchB.bat文件中运行batchA.bat和batchB.bat时相同的结果
例如callbatchA + B.batch,batchA.bat,batchB.bat
我通过运行
下面的concatfile.bat尝试了一个简单的concat
文件
copy callbatchA+B.bat+batchA.bat+batchB.bat combined_.bat
这不是以下concatenated
文件
::CallScript
CALL C:\Users\Myname\Desktop\batchA.bat
CALL C:\Users\Myname\Desktop\BatchB.bat
::ScriptA
@echo off
setlocal EnableDelayedExpansion
CD "C:\deviceno\"
::only change these three lines
set "start=295" ::starts from this number
set "amount=10" ::amount of files created
set "length=5" ::
set /a "last=%start%+%amount%"
for /l %%i in (%start%,1,%last%) do (
set "folderName=0000000000%%i"
set "folderName=!folderName:~-%length%!"
md "!folderName!"
)
pausefor
::ScriptB
/D %%a in ("C:\deviceno\*.*") do xcopy /y /d C:\Source\*.*"%%a\"
我尝试使用goto :eof
编辑代码,如下所示,但到目前为止我没有运气。
::ScriptA
@echo off
setlocal EnableDelayedExpansion
CD "C:\device_numbers\"
::only change these three lines
set "start=295" ::starts from this number
set "amount=10" ::amount of files created
set "length=5" ::
set /a "last=%start%+%amount%"
for /l %%i in (%start%,1,%last%) do (
set "folderName=0000000000%%i"
set "folderName=!folderName:~-%length%!"
md "!folderName!"
) DO CALL ::ScriptB
::ScriptB
p /D %%a in ("C:\device_numbers\*.*") do xcopy /y /d C:\Source\*.*"%%a\"
goto :eof
答案 0 :(得分:2)
我认为你正在尝试这样做:
::CallScript
@echo off
CALL :ScriptA
CALL :ScriptB
pause
goto :eof
:ScriptA
setlocal EnableDelayedExpansion
CD "C:\deviceno\"
::only change these three lines
set "start=295" ::starts from this number
set "amount=10" ::amount of files created
set "length=5" ::length of fileNames
set /a "last=%start%+%amount%"
for /l %%i in (%start%,1,%last%) do (
set "folderName=0000000000%%i"
set "folderName=!folderName:~-%length%!"
md "!folderName!"
)
goto :eof
:ScriptB
for /D %%a in ("C:\deviceno\*.*") do xcopy /y /d "C:\Source\*.*" "%%a\"
goto :eof
这是一个文件,使用子程序进行文件创建和复制。
我建议查看this以便更好地了解调用标签的工作原理
答案 1 :(得分:0)
也许是这样的事情?
@ECHO off
SETLOCAL
:: set up some data items for demo
SET /a fred=3
SET /a joe=8
SET /a charlie=10
CALL external add result %fred% %charlie%
ECHO %result%
CALL external add result %fred% %charlie% %joe%
ECHO %result%
CALL external subtract result %fred% %charlie%
ECHO %result%
CALL external concatenate result %fred% xyz %charlie%
ECHO %result%
GOTO :EOF
<强> external.bat
:: @echo off
setlocal enabledelayedexpansion
goto %*
:add
shift
set $=%1&shift
set /a $t=0
:addloop
set /a $t+=%1
shift
if "%1" neq "" goto addloop
:commonexit
endlocal&set %$%=%$t%
goto :eof
:subtract
shift
set $=%1&shift
set /a $t=%1-%2
goto commonexit
:concatenate
shift
set $=%1&shift
set "$t="
:concatloop
set "$t=%$t%%1"
shift
if "%1" neq "" goto concatloop
goto commonexit
答案 2 :(得分:-1)
你的意思是?
运行batchA.bat
并将管道batchA.bat
输出到batchB.bat
,然后运行batchB.bat
batchA | batchB
或运行batchA.bat
,然后运行batchB.bat
batchA & batchB