2015-02-03 4 views
0

다음은 시나리오입니다. 예를 들어 pairing.txt에 나열된 파일 목록이 있습니다. 이제 나열된 모든 파일을 비교 한 다음 보고서를 생성합니다. 이제는 사용자가 하나의 보고서에 원하는 파일 수를 사용자가 활성화 할 수있는 기능을 원합니다. 예를 들어 205 개의 파일이 나열되어 있습니다.배치 스크 립트를 사용하여 100 개 파일마다 보고서를 생성하는 방법

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에 나열된 파일을 얻을 비교할 수없는 사용하여 비교합니다. 이제 기본적으로 모든 비교가 1 html 보고서에 표시됩니다. 사용자가 모든 HTML 보고서에 표시 할 파일 수를 입력 할 수 있도록하려면 어떻게해야합니까?

답변

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 개의 파일을 입력했습니다. 남은 두 파일은 어떻습니까? 이 절 최종 출력 파일에서

유일한 스크립트가 변경

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 
+0

어떻게 초과하는 파일에 대한? 예를 들어 파일 목록이 12 개 인 경우 각 보고서에 대해 10 개의 파일을 입력했습니다. 남은 두 파일은 어떻습니까? – PeterS

+0

나는 아직도 그것을 기울이지 않는다. 코드가 라인별로 어떻게 작동하는지 알 수 있습니까? – PeterS

+0

무슨 일이 일어나는지 보려면': myType' 레이블 옆에'echo % Counter % % ReportNo %'명령을 추가하거나 옆에': myType'과'echo off> nul' 옆에'echo on> nul'을 추가하십시오 '%% Counter % EQU 0 set/A "ReportNo + = 1"'줄 ('goto : eof' 이전) ... – JosefZ