です。
@echo off
setlocal
set "ListFiles=%~dp0FileList.txt"
set "ListExist=%~dp0Exist.txt"
set "ListMissing=%~dp0NotExist.txt"
set "ListExtra=%~dp0Extra.txt"
set "ListCurrent=%TEMP%\ListCurrent.tmp"
rem Get list of all files in current directory and its subdirectories with
rem full path into a temporary list file. If the current directory tree
rem contains no file, delete empty list file and exit batch processing.
dir /A-D /B /ON /S >"%ListCurrent%" 2>nul
if errorlevel 1 (
copy "%ListFiles%" "%ListMissing%" >nul
if exist "%ListExist%" del "%ListExist%"
if exist "%ListExtra%" del "%ListExtra%"
goto EndBatch
)
%SystemRoot%\System32\findstr.exe /I /L /X /G:"%ListFiles%" "%ListCurrent%" >"%ListExist%"
%SystemRoot%\System32\findstr.exe /I /L /X /V /G:"%ListExist%" "%ListFiles%" >"%ListMissing%"
%SystemRoot%\System32\findstr.exe /I /L /X /V /G:"%ListExist%" "%ListCurrent%" >"%ListExtra%"
:EndBatch
del "%ListCurrent%"
endlocal
このバッチコードは、バッチファイルのディレクトリにFileList.txt
は、完全なパスとファイル名が含まれていることが必要です。
注:%~dp0
は、バックスラッシュで既に終わっているバッチファイルのパスに展開されます。したがって、ファイル名の前に余分なバックスラッシュを指定しないでください。
使用されているコマンドとその動作方法を理解するには、コマンドプロンプトウィンドウを開き、次のコマンドを実行して、コマンドごとに表示されているすべてのヘルプページをすべてよく読んでください。
copy /?
del /?
dir /?
echo /?
endlocal /?
findstr /?
...最も重要なリストの仕事をフィルタリングする方法を理解します。
goto /?
if /?
rem /?
set /?
setlocal /?
も>
、>nul
と2>nul
の説明についてUsing command redirection operatorsに関するMicrosoftの記事を参照してください。
あなたは 'findstr'コマンドに興味があるかもしれません:'ます。findstr/X/L/C: "FILE_NAME" "filelist.txtは、" ''場合には '0'の 'ErrorLevel'を返しfile_name'が持っていますそうでなければ 'filelist.txt'と' 1'の中に見つかりました。コマンドプロンプトウィンドウで 'findstr /?'と入力してください。 – aschipfl