2015-09-23 201 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