0

これがシナリオです。たとえば、pairing.txt にリストされているファイルのリストがあります。現在、リストされているすべてのファイルを比較し、レポートを生成しています。ここで、ユーザーが 1 つのレポートに必要なファイル数を有効にする機能が必要です。たとえば、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

唯一のスクリプトの変更に注意してください。

  • CountNoReportNo洞察を深めるために、変数の名前が に変更されました。
  • ReportNo1(問題の指示を観察するために)に開始されました。

編集2set /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 に答える