我正在尝试编写一个批处理文件,该文件将从包含列表的txt文件中读取行/行。然后批处理文件将复制匹配的文档,并生成丢失文件列表。
到目前为止,代码成功地复制了它匹配的文件,但它也填充了“Missing.txt”文件,它将精确输入列表的内容,而不仅仅是丢失的文件。
@echo off
::Requests name of list file to be used by batch file
echo Enter list file name and press enter
set /p var=
mkdir %userprofile%\Desktop\%var%\
set /A lis=1
::Logic to search for files based on contents of list inputted by user at start.
for /f "tokens=*" %%i in (%var%.txt) DO (
call :processline %%i
IF NOT EXIST %%i (echo %%i>>%userprofile%\Desktop\%var%\Missing.txt)
)
pause
::Function called processline
::Assigns a string/value to variable "line"
::Copies a file with name = "line" to the user's desktop
::Renames the file to include a number reference, based on original list being searched
::Increments number for next file to be searched,copies and renamed
:processline
echo line=%*
xcopy /s %*.* %userprofile%\Desktop\%var%
move /Y %userprofile%\Desktop\%var%\%*.pdf %userprofile%\Desktop\%var%\%lis%_%*.pdf
set /A lis=%lis%+1
:eof
我怀疑我的问题在“for”逻辑中,尽管可能有一种方法在processline函数中输入缺少的文件名。
非常感谢任何帮助或建议。
答案 0 :(得分:0)
这是命令顺序::processline
子程序移动一些东西,可能包括%%i
文件。我将使用下一个代码段:
IF EXIST "%%~i" (
call :processline %%i
) ELSE (
>>"%userprofile%\Desktop\%var%\Missing.txt" echo %%i
)