简体   繁体   English

批处理文件以对文件排序并列出缺失

[英]Batch file to sort files and list missing

I am trying to write a batch file that would read rows/lines from a txt file containing a list. 我正在尝试编写一个批处理文件,该文件将从包含列表的txt文件中读取行/行。 The batch file would then copy the documents that match, and produce a list of missing files. 然后,批处理文件将复制匹配的文档,并生成丢失文件的列表。

So far, the code successfully copies the files that it matches, but it also fills the "Missing.txt" file will exact contents of the input list, rather than simply the missing files. 到目前为止,该代码已成功复制了它匹配的文件,但是它也填充了“ 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

I suspect my problem is within the "for" logic, although there might be a way to input missing file names within the processline function. 我怀疑我的问题出在“ for”逻辑之内,尽管可能有一种方法可以在processline函数中输入缺少的文件名。

Any help or advice would be much appreciated. 任何帮助或建议,将不胜感激。

It's command order: :processline subroutine moves something, maybe including %%i file. 它是命令顺序:: :processline子例程移动某些内容,可能包括%%i文件。 I'd use next code snippet: 我将使用下一个代码段:

IF EXIST "%%~i" (
    call :processline %%i
) ELSE (
    >>"%userprofile%\Desktop\%var%\Missing.txt" echo %%i
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM