2013-05-02 127 views
0

我试图做一个批处理文件,将比较两个文件夹“核心”和“自定义”,并返回不在的文件的名称定制。批处理文件比较两个文件夹返回不在一个文件夹中的文件

到目前为止,我有这段代码,其中大部分是从堆栈溢出的另一个问题。它创建每个文件夹中文件的“阵列”。我如何比较它们?

@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 

回答

0

怎么样

echo y|xcopy /l /d core\* custom\ 

应列出所有的核心不在定制的或不同的版本在核心中的文件?

2

这里是另一种选择:

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

解决方案与“阵列”和菜单:

@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 

这不能与=处理文件名,如果是必要的代码可以修改。

相关问题