Problem I want to solve: Compare files in one directory to files in a subdirectory. If they match, delete the file in the top directory. This is for Windows and I would like to use Windows Batch commands. If the file doesn't exist, the script will exit.
For example: c:\temp contains baz_foo.exe c:\temp\bar contains foo.exe
Attempt to copy foo.exe to c:\temp\bar, but robocopy notices they're the same, so it will exit and give a return code of 0. https://blogs.technet.microsoft.com/deploymentguys/2008/06/16/robocopy-exit-codes/
@echo off setlocal enabledelayedexpansion SET ARCHIVEDIR=c:\temp\bar FOR %%F in ('*baz_foo*.exe') DO SET ( ROBOCOPY . %ARCHIVEDIR% %%F if errorlevel 0 goto nocopy if errorlevel 1 goto copy :nocopy echo Files are identical goto exit :copy echo files different goto exit ) :exit Call nextfile.bat
Clarification: Note, I don't need the files copied to bar, I just want to know if they're the same or different. If it's the same, delete from c:\temp and move onto the next file; at the end of finding all files, call a different script.