对于循环结束批处理文件执行

时间:2018-02-09 20:36:28

标签: batch-file for-loop

我的批处理文件在第一个循环(for /d "delims= eol=|" %%d in (*.*) do ()上静默地结束执行,我不知道为什么。

  • 我没有调用任何其他批处理文件
  • 我的子文件夹名称包含空格,我试图用"delims= eol=|"
  • 处理

我从未看到!parent!!folder!回显,并且最后没有停顿。我做错了什么?

@Echo off
setlocal enabledelayedexpansion

pushd "%~dp0"

set "parent=%~dp0"
echo !parent!
set "destination=\\(test destination folder)\"

rem SET "destination=\\(prod destination folder)\"


set "FileCount=0"


for /d "delims= eol=|" %%d in (*.*) do (
    set "folder=%%d"
    echo !parent!!folder!
    pause
    for %%f in ("!parent!!folder!\(file identifying-pattern)*.DAT") do (
        echo "File Type 1"
        pause
        if !FileCount! lss 200 ( 
            set /a !FileCount!+=1
            ECHO !FileCount!
            ECHO !parent!!folder!%%f
            ECHO !destination!%%f
            MOVE "%%f" "!destination!"
        )
    (
    for %%f in ("!parent!!folder!\(file identifying-pattern)*.DAT") do (
        echo "File Type 2"
        pause
        if !FileCount! lss 200 ( 
            set /a !FileCount!+=1
            ECHO !FileCount!
            ECHO !parent!!folder!%%f
            ECHO !destination!%%f
            MOVE "%%f" "!destination!"
        )
    )
)


for /d %%d in (*.*) do (
set "folder=%%d"
if not %%d==Archive (
if not %%d==Hold (

dir /b "!folder!"|find /v "">nul && ECHO "!folder! NOT EMPTY"||rmdir "!parent!!folder!"

)
)
)


pause

popd

1 个答案:

答案 0 :(得分:1)

我猜测你在做什么,试图不要过多地改变结构

您需要在行45上添加目的地,并根据需要将文件模式添加到行89(请确保不要使用反斜杠结束目标路径)

@Echo Off
CD /D "%~dp0" 2>Nul || Exit /B

Set "Destination=\\(test destination folder)"
Rem Set "Destination=\\(prod destination folder)"
If Not Exist "%destination%\" Exit /B

Set "Pattern1=(file identifying-pattern)"
Set "Pattern2=(file identifying-pattern)"

Set /A Type1Count=Type2Count=0
SetLocal EnableDelayedExpansion
For /D %%A In (*) Do (
    For %%B In ("%%A\%Pattern1%*.dat") Do (
        Echo "File Type 1"
        Set /A Type1Count +=1
        If !Type1Count! Lss 200 (
            Echo !Type1Count!. "%CD%\%%A\%%B" --^> "%Destination%\%%B"
            If Not Exist "%Destination%\%%B\" MD "%Destination%\%%B"
            Move /Y "%%B" "%Destination%\%%B">Nul
        )
    )
    For %%C In ("%%A\%Pattern2%*.dat") Do (
        Echo "File Type 2"
        Set /A Type2Count +=1
        If !Type2Count! Lss 200 (
            Echo !Type2Count!. "%CD%\%%B\%%C" --^> "%Destination%\%%C"
            If Not Exist "%Destination%\%%C\" MD "%Destination%\%%C"
            Move /Y "%%C" "%Destination%\%%C">Nul
        )
    )
    If /I Not "%%A"=="Archive" (
        If /I Not "%%A"=="Hold" (
            Set "file="
            For %%D In (*) Do Set "file=1"
            If Defined file (Echo %%A NOT EMPTY) Else RD "%%A" 2>Nul
        )
    )
)

Pause

如果您在测试中对此感到满意,可以Rem方舟4Rem方舟行5