Windows 如何验证文件夹(批处理脚本)中是否缺少文件?

Windows 如何验证文件夹(批处理脚本)中是否缺少文件?,windows,batch-file,Windows,Batch File,我有一个文本文件中的文件名列表。比如说filename.txt 还有一个文件夹,上面写着C:\Files 我想制作一个批处理脚本,它将使用filename.txt中的文件名列表检查文件夹C:\Files,如果任何文件丢失,它将给出报告或将丢失的文件名保存在文本文件中并保存它 对不起,我不知道该怎么做。如果有人能帮助我,那将非常有帮助。试试这个。我对代码进行了注释,希望它是不言自明的 @ECHO OFF GOTO :Main :: =================================

我有一个文本文件中的文件名列表。比如说
filename.txt
还有一个文件夹,上面写着
C:\Files
我想制作一个批处理脚本,它将使用
filename.txt
中的文件名列表检查文件夹
C:\Files
,如果任何文件丢失,它将给出报告或将丢失的文件名保存在文本文件中并保存它


对不起,我不知道该怎么做。如果有人能帮助我,那将非常有帮助。

试试这个。我对代码进行了注释,希望它是不言自明的

@ECHO OFF
GOTO :Main
:: ======================================================================
:: For each filename in file 'fname', find all that are missing from the
:: directory specified by 'dname'.
::
:: Filenames in 'fname' are one per line, spaces are allowed in a filename.
:: Filenames in 'fname' are relative paths to the directory specified.
::     i.e. to search for files blarg and foo\bar.txt under the directory
::          C:\TEMP
::
::     'fname' will contain
::         blarg
::         foo\bar.txt
::
::     and 'dname' will be passed as C:\TEMP
::
:: Note if the entry in filename matches a directory, that will return success
:: too. This finds missing files and directories.

:Main
SETLOCAL
    SET "FNAME=%~1"
    SET "DNAME=%~2"

    :: invoke findFile for each line in the file
    FOR /F "tokens=*" %%F IN (%FNAME%) DO (
        CALL :findFile "%DNAME%" "%%~F"
    )


(ENDLOCAL
 EXIT /B 0)



:findFile
SETLOCAL
    SET "DNAME=%~1"
    SET "FNAME=%~2"

    :: Paste the folder to search with the file to find.
    IF NOT EXIST "%DNAME%\%FNAME%" (
        ECHO %FNAME% IS MISSING!!!!
    ) ELSE (
        ECHO found %FNAME%
    )
(ENDLOCAL
 EXIT /B 0)

键入
以获取/?
如果/?
以获取帮助。