如何在窗口批处理中循环时执行



我编写了一个Windows批处理脚本,根据我放入名为list.txt的记事本文件中的列表检查文件并将其移动到另一个目录。但我不知道如何设置 while-loop。只有在满足条件时才能跳出子路由。

在 C 编程中,我们可以通过直接设置 while 循环来编写这样的代码。但似乎在窗口批处理中是完全不同的。

我想要的就是这样:

目录 A:

 1. A.txt 
 2. B.txt 
 3. list.txt (By line sequential with filename want to move) 
 4. process.bat

目录 B:

  1. 没有文件(然后按列表中设置的行顺序移动文件.txt)或
  2. A.txt(如果目录中已经存在文本文件,进程.bat将在A.txt消失之前暂停)

过程.bat

@echo off
:readline
for /f "tokens=*" %%a in (list.txt) do call :processline %%a
goto :eof
:processline
if exist D:DirectoryA*.txt (
echo %time% >> D:AutoLogLog.txt
echo Previous job did not finished yet. >> D:AutoLogLog.txt
Timeout /t 30 
echo.
)
set name=%*
if exist %name%.txt (
echo %time% >> D:AutoLogLog.txt
echo File found and processing   %name%.txt   now... >> D:AutoLogLog.txt
copy "%~dp0%name%.txt" "D:DirectoryB"
echo Transfer   %name%.txt   completed!! >> D:AutoLogLog.txt
echo. >> D:AutoLogLog.txt
Timeout /t 790
echo.
echo ==============================================================
)
:eof

请指导我使用 while-loop 方法完成脚本。谢谢

我更改了一些脚本序列,它现在可以工作了。

@echo off
:readline
for /f "tokens=*" %%a in (list.txt) do call :processline %%a
goto :eof
:processline
set name=%*
if exist C:Test2*.txt (
        echo %date% %time% >> C:Test2Log.txt
        echo Previous job did not finished yet. >> C:Test2Log.txt
        Timeout /t 5
        echo.
        echo. >> C:Test2Log.txt
        goto :processline
         )
if exist %name%.txt (
echo %date% %time% >> C:Test2Log.txt
echo File found and processing   %name%.txt   now... >> C:Test2Log.txt
copy "%~dp0%name%.txt" "C:Test2"
echo Transfer   %name%.txt   completed!! >> C:Test2Log.txt
echo. >> C:Test2Log.txt
Timeout /t 10
echo.
echo ==============================================================
)
:eof

这将复制并计算文本文件中的行数。

@ echo off 
:TextPath
cls
set /p Input=#1 Enter the full path of the text file :
set /p Source=#2 Enter the full path of Source :
set /p Target=#3 Enter the full path of Destination :
:choice
set /P c=Ready to Continue[Y/N]?
if /I "%c%" EQU "Y" goto :Yes
if /I "%c%" EQU "N" goto :No
goto :choice
:Yes_Local
for /f "delims=" %%i in (%Input%) do echo f| xcopy /f /y  "%Source%%%i" "%Target%%%i"
for /f %%C in ('Find /V /C "" ^< %Input%') do set Count=%%C
msg * No of Lines executed= %Count%
exit
:No
cls
color e
echo Redirecting to Main....
PING 127.0.0.1 -n 2 >NUL
cls
echo Please wait
PING 127.0.0.1 -n 4 >NUL
goto TextPath

相关内容

  • 没有找到相关文章

最新更新