@echo off setlocal EnableDelayedExpansion for %%i in ("%cd%\first\*.*") do ( set uniq=0 for /f %%x in ('crc32 %%i -nf') do ( set one=%%x call:find_two "%%i" ) if !uniq!==1 ( echo %%i >>result.txt ) :next ) exit :find_two for %%j in ("%cd%\second\*.*") do ( for /f %%x in ('crc32 %%j -nf') do ( set two=%%x call:compare "%%j" ) ) goto:eof :compare if !one!==!two! ( goto next ) else ( set uniq=1 ) goto:eof