Batch file 批处理文件输出

Batch file 批处理文件输出,batch-file,Batch File,我有一个批处理文件,它读取文本文件以获取文档位置,然后将物理文件复制到本地文件夹。我需要包括的是,如果物理文件不存在,我需要将文档详细信息从文本文件输出到另一个文件,这样我就有一个缺少文档的列表。我希望这是有道理的 这是我的批处理文件内容 SET destfolder=e:\data FOR /F "delims=" %%a IN (e:\cn_documents.csv) DO COPY "%%a" "%destfolder%\%%~nxa" 听起来您只需要在复制之前检查文件是否存在。如果存

我有一个批处理文件,它读取文本文件以获取文档位置,然后将物理文件复制到本地文件夹。我需要包括的是,如果物理文件不存在,我需要将文档详细信息从文本文件输出到另一个文件,这样我就有一个缺少文档的列表。我希望这是有道理的

这是我的批处理文件内容

SET destfolder=e:\data
FOR /F "delims=" %%a IN (e:\cn_documents.csv) DO COPY "%%a" "%destfolder%\%%~nxa"

听起来您只需要在复制之前检查文件是否存在。如果存在条件,则可使用条件完成此操作

SET destfolder=e:\data
SET DoesNotExistList="E:\DoesNotExist.txt"

REM Reset the not exist list so it doesn't pile up from multiple runs.
ECHO The following files were not found > %DoesNotExistList%

FOR /F "delims=" %%a IN (e:\cn_documents.csv) DO (
    REM Check if the file exists.
    IF EXIST "%%a" (
        REM It does exist, copy to the destination.
        COPY "%%a" "%destfolder%\%%~nxa"
    ) ELSE (
        REM It does not exist, note the file name.
        ECHO %%a>>%DoesNotExistList%
    )
)

好的-如果我读对了,你想创建一个“日志文件”来记录在这个for循环中丢失的位置吗?非常感谢Jason,这正是我需要的