同名ファイルの内容比較と振り分けバッチ

バッチファイル

@echo off
setlocal enabledelayedexpansion

set "SRC1=Y:\output_txt"
set "SRC2=Y:\output_txtC"
set "SAME=Y:\same_files"
set "DIFF=Y:\diff_files"

:: フォルダーがなければ作成
if not exist "%SAME%" mkdir "%SAME%"
if not exist "%DIFF%" mkdir "%DIFF%"

:: output_txt 内のファイルをループ
for %%F in ("%SRC1%\*") do (
    set "FILENAME=%%~nxF"
    if exist "%SRC2%\!FILENAME!" (
        fc /b "%%F" "%SRC2%\!FILENAME!" >nul
        if !errorlevel! == 0 (
            echo SAME: !FILENAME!
            move /Y "%%F" "%SAME%\"
        ) else (
            echo DIFF: !FILENAME!
            move /Y "%%F" "%DIFF%\"
        )
    )
)

echo 完了しました!
pause

bat

Posted by eightban