作者:星痕之刃 | 来源:互联网 | 2023-06-06 14:19
IwroteawindowsbatchscripttocheckandmovefilestoanotherdirectorybasedonthelistIput
I wrote a windows batch script to check and move files to another directory based on the list I put in a notepad file named list.txt. But I have no idea that how to set the while-loop. Only to jump out of the subroute when the condition fulfill.
我编写了一个windows批处理脚本,根据我在一个名为list.txt的记事本文件中的列表来检查和移动文件到另一个目录。但是我不知道如何设置while循环。只有当条件满足时才跳出子程序。
In C Programming, we could write like this by setting a while-loop direcly. But seems in windows batch is quite different.
在C编程中,我们可以通过直接设置一个while循环来这样写。但是在windows的批次中似乎是完全不同的。
All I want is like this:
我想要的就是这样:
Directory A:
目录:
1. A.txt
2. B.txt
3. list.txt (By line sequential with filename want to move)
4. process.bat
Directory B:
目录B:
- None of files (Then move a file by order of line set in list.txt) OR
- 没有文件(然后按照list.txt中的行集顺序移动文件)。
- A.txt (If already existed a text file in directory, process.bat will pause before A.txt disappear)
- 一个。txt(如果在目录中已经存在一个文本文件,则处理。蝙蝠会在A之前停下来。txt消失)
Process.bat
Process.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:\AutoLog\Log.txt
echo Previous job did not finished yet. >> D:\AutoLog\Log.txt
Timeout /t 30
echo.
)
set name=%*
if exist %name%.txt (
echo %time% >> D:\AutoLog\Log.txt
echo File found and processing %name%.txt now... >> D:\AutoLog\Log.txt
copy "%~dp0\%name%.txt" "D:\DirectoryB"
echo Transfer %name%.txt completed!! >> D:\AutoLog\Log.txt
echo. >> D:\AutoLog\Log.txt
Timeout /t 790
echo.
echo ==============================================================
)
:eof
Please guide me to finish the script by using a while-loop method. Thanks
请引导我使用while循环方法完成脚本。谢谢
2 个解决方案