2015-09-23 203 views
-1

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

这里是我的批处理文件内容

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

好的 - 所以如果我正在阅读这个权利,你想创建一个“日志文件”的位置,这是错过了这个for循环? –

回答

0

这听起来像所有你需要的是简单地检查文件复制之前就存在。这可以通过IF EXIST条件来完成。

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% 
    ) 
) 
+0

非常感谢杰森,那正是我所需要的 – user5367782