2016-02-25 128 views
1

嗨,我想分两批处理脚本并将它们合并为一个。我也想要现在的“One”批处理文件以降序运行。如何合并两个批处理脚本,将它们放到一个批处理文件中并以降序运行

我能够但是使用CALL功能,那么我有三个批处理文件。

我试图将它们结合起来并达到相同的结果,我想如果我不得不从callbatchA + batchB.bat运行batchA.bat和batchB.bat文件

如callbatchA + B.batch ,batchA.bat,batchB.bat

我通过运行concatfile.bat包括以下

copy callbatchA+B.bat+batchA.bat+batchB.bat combined_.bat 

这并没有尝试过的文件的简单concat下面

::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\" 

concatenated文件将不起作用的例子,我试图与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 

回答

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

完美,谢谢! – Jonas

-1

您的意思是?

运行batchA.bat和管道batchA.bat输出到batchB.bat,然后运行batchB.bat

batchA | batchB 

或运行batchA.bat,然后运行batchB.bat

batchA & batchB 
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 
相关问题