0

Here's the scenario, for example I have list of files listed in pairing.txt. Now I am doing comparison for all the files listed then generating reports. Now, I want to have a feature that will enable the user how many files he want for one report. For example, I have 205 files listed.

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

Here my actual code

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
)

What it does is, It will get the files listed in pairing.txt and compare it using beyond compare. Now by default, all comparison will be displayed in 1 html report. What if I want the user to have the option to enter how many files he want to display in every html report?

PeterS
  • 724
  • 2
  • 15
  • 31

1 Answers1

1

Supposing correctness of the code provided in question, an user input expected in set /P command and tested whether numeric and positive; output file numbering is done in the :myType subroutine as follows:

:: 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

Final output files should be

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

Edit: according to OP's comment: For example I have 12 list of files, then I entered 10 files for each report. How about the remaining 2 files?

Under that clause final output files should be

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

Note the only script changes:

  • CountNo variable renamed to ReportNo for better insight;
  • ReportNo initiated to 1 (to observe instructions in question).

Edit 2: I had forgotten set /a command provides (32 bit signed) integer arithmetic, so the :myType procedure could be simplified as follows:

:myType
  set /A "ReportNo=(%Counter%-1)/%howmany%+1"
  type  c:\user\report.html >> c:\user\report\Report%ReportNo%.html
goto :eof
JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • How about the excess file? For example I have 12 list of files, then I entered 10 files for each report. How about the remaining 2 files? – PeterS Feb 03 '15 at 14:07
  • I still cant get it working. May I know how the codes work line by line? – PeterS Feb 04 '15 at 08:32
  • To see what does happen: either add `echo %Counter% %ReportNo%` command next to `:myType` label, or add `echo on>nul` next to `:myType` and `echo off>nul` next to `if %Counter% EQU 0 set /A "ReportNo+=1"` line (before `goto :eof`)... – JosefZ Feb 04 '15 at 08:54
  • I would like to ask if what if I entered 150? I noticed that you have declared set /A "howmany=100" and set /A "howmany%%=100000"? BTW its working now :) – PeterS Feb 04 '15 at 10:02
  • `set /A "howmany%%=100000"` meaning: if a user type a non-numeric value in response to `set /P "howmany=how many files ..."`, then `%howmany%` results to this non-numeric value but used in an arithmetic expression then results to _zero_. You could choose any sufficiently great number instead of `100000`... `%%` operator gives _modulus_ i.e. the remainder after division. – JosefZ Feb 04 '15 at 10:36