我正在尝试制作一个批处理文件,用于比较两个文件夹“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
答案 0 :(得分:2)
这是另一种选择:
@echo off
for %%a in ("core\*.*") do (
if not exist "custom\%%~nxa" echo missing in custom - "%%a"
)
答案 1 :(得分:0)
怎么样
echo y|xcopy /l /d core\* custom\
应该列出核心中没有自定义或不同版本的所有核心文件?
答案 2 :(得分: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
这无法处理=
的文件名,如果有必要,可以修改代码。