I'm trying to make a batch file that will compare two folders "core" and "custom" and return the names of the files that aren't in custom.
So far I have this code, most of which is taken form another question on stack overflow. It creates "Arrays" of the files in each folder. How can I compare them?
@echo off
setlocal enableDelayedExpansion
::build "array" of folders
set folderCnt=0
for /f "eol=: delims=" %%F in ('dir /B core') do (
set /a folderCnt+=1
set "folder!folderCnt!=%%F"
)
::print menu
for /l %%M in (1 1 %folderCnt%) do echo %%M - !folder%%M!
echo(
::build "array" of folders
set folderCnt=0
for /f "eol=: delims=" %%F in ('dir /B custom') do (
set /a folderCnt+=1
set "folder!folderCnt!=%%F"
)
::print menu
for /l %%N in (1 1 %folderCnt%) do echo %%N - !folder%%N!
echo(
pause
test.bat
how about
echo y|xcopy /l /d core\* custom\
which should list all the files in core that are not in custom or a different version is in core?
Here is another option:
@echo off
for %%a in ("core\*.*") do (
if not exist "custom\%%~nxa" echo missing in custom - "%%a"
)
Solution with "arrays" and menu:
@echo off &setlocal
for /f "tokens=1*delims=:" %%i in ('dir /b /a-d core ^| findstr /n "^"') do set "#%%i=%%j"
for /f "tokens=1*delims==#" %%i in ('set "#"') do echo core: %%i %%j
for /f "tokens=1*delims=:" %%i in ('dir /b /a-d custom ^| findstr /n "^"') do set "$%%i=%%j"
for /f "tokens=1*delims==$" %%i in ('set "$"') do echo custom: %%i %%j
for /f "delims=" %%i in ('dir /b /a-d custom') do set "_%%i=%%i"
for /f "tokens=1*delims==#" %%i in ('set "#"') do if not defined _%%j echo missing: %%i %%j
This can't handle file names with =
, if that is necessary the code can be modified.