0

这是场景,例如我在pairing.txt 中列出了文件列表。现在我正在对列出的所有文件进行比较,然后生成报告。现在,我想要一个功能,使用户能够为一份报告提供多少个文件。例如,我列出了 205 个文件。

FIRST 100 -    Report1.html
NEXT 100 -     Report2.html
Remaining 5 -  Report3.html

这是我的实际代码

for /f "tokens=2-4" %%a in ('type c:\user\pairing.txt') do (
  set /A Counter+=1
  echo Processing  ColumnA : %%a  ColumnB: %%b 
  echo  Processing  ColumnA : %%a  ColumnB: %%b >>comparison.log
  %varBCpath% %varBCscript% c:\user\ColumnA\%%a c:\user\ColumnB\%%b "c:\comp\report.html" "%title%" /silent
  type  c:\user\report.html >> c:\user\report\Report.html
)

它的作用是,它将获取pairing.txt 中列出的文件并使用beyond compare 进行比较。现在默认情况下,所有比较都将显示在 1 个 html 报告中。如果我希望用户可以选择输入他想在每个 html 报告中显示的文件数怎么办?

4

1 回答 1

1

假设所提供代码的正确性,用户在set /P命令中输入预期并测试是否为数字和正数;输出文件编号在:myType子程序中完成如下:

:: some code here

:againhowmany
set /A "howmany=100"
set /P "howmany=how many files do you want for one report (Enter=%howmany%) "
set /A "howmany%%=100000"
if %howmany% LEQ 0 goto :againhowmany 

set /A "Counter=0"
set /A "ReportNo=1"

for /f "tokens=2-4" %%a in ('type c:\user\pairing.txt') do (
  set /A "Counter+=1"
  echo Processing  ColumnA : %%a  ColumnB: %%b 
  echo  Processing  ColumnA : %%a  ColumnB: %%b >>comparison.log
  %varBCpath% %varBCscript% c:\user\ColumnA\%%a c:\user\ColumnB\%%b "c:\comp\report.html" "%title%" /silent
  call :myType
)

:: some code here 
goto :eof

:myType
  type  c:\user\report.html >> c:\user\report\Report%ReportNo%.html
  set /A "Counter%%=%howmany%"
  if %Counter% EQU 0 set /A "ReportNo+=1" 
goto :eof

最终输出文件应该是

c:\user\report\Report1.html
c:\user\report\Report2.html
c:\user\report\Report3.html
...

编辑:根据 OP 的评论:例如我有 12 个文件列表,然后我为每个报告输入 10 个文件。剩下的2个文件呢?

根据该条款,最终输出文件应为

Report1.html   - files (pair)  1..10
Report2.html   - files (pair) 11..12

请注意唯一的脚本更改:

  • CountNo变量重命名为以ReportNo获得更好的洞察力;
  • ReportNo开始1(遵守相关指示)。

编辑 2:我忘记set /a了命令提供(32 位有符号)整数运算,因此 :myType可以将过程简化如下:

:myType
  set /A "ReportNo=(%Counter%-1)/%howmany%+1"
  type  c:\user\report.html >> c:\user\report\Report%ReportNo%.html
goto :eof
于 2015-02-03T13:28:35.993 回答