0

我正在尝试制作一个批处理文件,它将比较两个文件夹“core”和“custom”并返回非自定义文件的名称。

到目前为止,我有这段代码,其中大部分来自另一个关于堆栈溢出的问题。它在每个文件夹中创建文件的“数组”。我该如何比较它们?

@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
4

3 回答 3

2

这是另一种选择:

@echo off
for %%a in ("core\*.*") do (
if not exist "custom\%%~nxa" echo missing in custom - "%%a"
)
于 2013-05-03T06:23:06.763 回答
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

这无法处理带有 的文件名=,如果有必要,可以修改代码。

于 2013-05-03T06:50:09.083 回答
0

怎么样

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

哪个应该列出核心中所有不在自定义或不同版本中的文件?

于 2013-05-02T15:28:09.937 回答