BAT批处理——遍历两个文件夹并进行比对

@echo off

set file_path=C:\Users\Administrator\Desktop\cyberark\ReportParserOt
set log=C:\Users\Administrator\Desktop\cyberark\testOt.txt
for /r %file_path% %%i in (*.*) do ( 
	set file=%%i
	set file_size=%%~zi
	set file_mod_time=%%~ti 
	call :file_compare
)

:file_compare
set fileOther=%file:ReportParserOt=ReportParser%
set file_ti=%file_mod_time:~0,4%%file_mod_time:~5,2%%file_mod_time:~8,2%%file_mod_time:~11,5%
if exist %fileOther% ( 
for %%i in ("%fileOther%") do (
	set file_Ot_size=%%~zi
	set file_Ot_time=%%~ti
	call :file_comp
 )
) else ( echo %file% %file_size% %file_ti% %fileOther% >>%log% )
goto :eof

:file_comp
set file_tii=%file_Ot_time:~0,4%%file_Ot_time:~5,2%%file_Ot_time:~8,2%%file_Ot_time:~11,5%
if not "%file_size%"=="%file_Ot_size%" ( if "%file_ti%"=="%file_tii%" ( echo %file% %file_size% %file_ti% %fileOther% %file_Ot_size% %file_tii% >>%log% ))
if "%file_size%"=="%file_Ot_size%" ( if not "%file_ti%"=="%file_tii%" ( echo %file% %file_size% %file_ti% %fileOther% %file_Ot_size% %file_tii% >>%log% ))
if not "%file_size%"=="%file_Ot_size%" ( if not "%file_ti%"=="%file_tii%" ( echo %file% %file_size% %file_ti% %fileOther% %file_Ot_size% %file_tii% >>%log% ))
goto :eof

你可能感兴趣的:(cmd)