Batch file compare two folders return files that aren't in one folder

好久不见. 提交于 2019-12-25 03:08:40

问题


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

回答1:


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?




回答2:


Here is another option:

@echo off
for %%a in ("core\*.*") do (
if not exist "custom\%%~nxa" echo missing in custom - "%%a"
)



回答3:


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.



来源:https://stackoverflow.com/questions/16341468/batch-file-compare-two-folders-return-files-that-arent-in-one-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!