【问题标题】:Batch file compare two folders return files that aren't in one folder批处理文件比较两个文件夹返回不在一个文件夹中的文件
【发布时间】:2013-05-02 15:05:10
【问题描述】:

我正在尝试制作一个批处理文件,它将比较两个文件夹“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

【问题讨论】:

    标签: file batch-file command compare prompt


    【解决方案1】:

    这是另一种选择:

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

    【讨论】:

      【解决方案2】:

      怎么样

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

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

      【讨论】:

        【解决方案3】:

        “数组”和菜单的解决方案:

        @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
        

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-02-01
          • 2010-11-02
          • 2012-03-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多