I recently downloaded some e-books, and after extracting them they were all htm webpages. Since I want to package them into CHM format, I want to add pagination links to the webpages.

Suppose the htm filenames are: A, B, C, D, ... (these filenames are just assumed for the convenience of posting, don't misunderstand), and suppose the last one is S.
For example, the pagination links for the C file are as follows:
<table widtd="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td scope="col"><a href="A.htm">First page</a></td>
<td scope="col"><a href="B.htm">Previous page</a></td>
<td scope="col"><a href="A.htm">1</a></td>
<td scope="col"><a href="B.htm">2</a></td>
<td scope="col"><a href="C.htm">3</a></td>
<td scope="col"><a href="D.htm">4</a></td>
<td scope="col"><a href="E.htm">5</a></td>
<td scope="col"><a href="F.htm">Next page</a></td>
<td scope="col">3/19</td>
<td scope="col"><a href="S.htm">Last page</a></td>
</tr>
</table>
To keep the layout simpler, below is a simplified form, but the effect produced by the batch file should match the htm code above. The pagination rules are as follows: (the numbers below mean the filename's position after sorting by name, so A is 1, C is 3, F is 5, while the 19 in 1/19, 3/19, etc. is because we assume there are 19 files total)
A First page A A1 B2 C3 D4 E5 1/19 Last page S make up the four after it
B First page A A1 B2 C3 D4 E5 2/19 Last page S make up the three after it
C First page A A1 B2 C3 D4 E5 3/19 Last page S because there are two before and two after it, no compensation is needed
D First page A B2 C3 D4 E5 F6 4/19 Last page S
E First page A C3 D4 E5 F6 G7 5/19 Last page S
F First page A D4 E5 F6 G7 H8 6/19 Last page S
If S is the last one and its corresponding number is 19, then make up the four before it
S First page A O15 P16 Q17 R18 S19 Last page S
If R is the last one and its corresponding number is 19, then make up the three before it
R First page A O15 P16 Q17 R18 S19 Last page S
If Q is the third from last, then since it already has two before and two after it, no compensation is needed
Q First page A O15 P16 Q17 R18 S19 Last page S
All of the above is for when the file count is 5 or more
If there is only one file:
A A1 1/1
If there are two files:
A First page A A1 B2 1/2 Last page B make up one
A First page A A1 B2 2/2 Last page B
If there are three files:
A First page A A1 B2 C3 1/3 Last page C make up two
A First page A A1 B2 C3 2/3 Last page C make up one
C A First page A A1 B2 2/3 Last page C
If there are four files:
A First page A A1 B2 C3 D4 1/4 Last page D make up three
A First page A A1 B2 C3 D4 2/4 Last page D make up two
C First page A A1 B2 C3 D4 3/4 Last page D make up one
A First page A A1 B2 C3 D4 4/4 Last page D
I've been hanging around the forum for quite a while, but to realize the pagination above I actually have to make 5 separate batch files, so I'm asking the experts to help me write a batch file. Thanks!
[ Last edited by HAT on 2009-2-4 at 14:08 ]

Suppose the htm filenames are: A, B, C, D, ... (these filenames are just assumed for the convenience of posting, don't misunderstand), and suppose the last one is S.
For example, the pagination links for the C file are as follows:
<table widtd="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td scope="col"><a href="A.htm">First page</a></td>
<td scope="col"><a href="B.htm">Previous page</a></td>
<td scope="col"><a href="A.htm">1</a></td>
<td scope="col"><a href="B.htm">2</a></td>
<td scope="col"><a href="C.htm">3</a></td>
<td scope="col"><a href="D.htm">4</a></td>
<td scope="col"><a href="E.htm">5</a></td>
<td scope="col"><a href="F.htm">Next page</a></td>
<td scope="col">3/19</td>
<td scope="col"><a href="S.htm">Last page</a></td>
</tr>
</table>
To keep the layout simpler, below is a simplified form, but the effect produced by the batch file should match the htm code above. The pagination rules are as follows: (the numbers below mean the filename's position after sorting by name, so A is 1, C is 3, F is 5, while the 19 in 1/19, 3/19, etc. is because we assume there are 19 files total)
A First page A A1 B2 C3 D4 E5 1/19 Last page S make up the four after it
B First page A A1 B2 C3 D4 E5 2/19 Last page S make up the three after it
C First page A A1 B2 C3 D4 E5 3/19 Last page S because there are two before and two after it, no compensation is needed
D First page A B2 C3 D4 E5 F6 4/19 Last page S
E First page A C3 D4 E5 F6 G7 5/19 Last page S
F First page A D4 E5 F6 G7 H8 6/19 Last page S
If S is the last one and its corresponding number is 19, then make up the four before it
S First page A O15 P16 Q17 R18 S19 Last page S
If R is the last one and its corresponding number is 19, then make up the three before it
R First page A O15 P16 Q17 R18 S19 Last page S
If Q is the third from last, then since it already has two before and two after it, no compensation is needed
Q First page A O15 P16 Q17 R18 S19 Last page S
All of the above is for when the file count is 5 or more
If there is only one file:
A A1 1/1
If there are two files:
A First page A A1 B2 1/2 Last page B make up one
A First page A A1 B2 2/2 Last page B
If there are three files:
A First page A A1 B2 C3 1/3 Last page C make up two
A First page A A1 B2 C3 2/3 Last page C make up one
C A First page A A1 B2 2/3 Last page C
If there are four files:
A First page A A1 B2 C3 D4 1/4 Last page D make up three
A First page A A1 B2 C3 D4 2/4 Last page D make up two
C First page A A1 B2 C3 D4 3/4 Last page D make up one
A First page A A1 B2 C3 D4 4/4 Last page D
I've been hanging around the forum for quite a while, but to realize the pagination above I actually have to make 5 separate batch files, so I'm asking the experts to help me write a batch file. Thanks!
[ Last edited by HAT on 2009-2-4 at 14:08 ]

