There are several files in a certain folder. For example, there are 5 files from A to E. After sorting by name, read the file names and put them into the text, and save them according to the file name. For example, A is saved as A.txt, and similarly B is B.txt. The content of A.txt is <var>A</var> <var>B</var> <var>C</var>
The content of B.txt is as follows
<var>A</var> <var>B</var> <var>C</var>
The content of C.txt is as follows
<var>B</var> <var>C</var> <var>D</var>
The content of D.txt is as follows
<var>C</var> <var>D</var> <var>E</var>
The content of E.txt is as follows
<var>C</var> <var>D</var> <var>E</var>
Please pay attention to the part in blue. Except for the first and the last, the text file name is in the middle. The left is the previous one after sorting by name, right is the next one after sorting by name. Except for the first and the last, the following code can already be displayed
Let A.txt be the first file, and the content is <var>A<tr>1</tr></var> <var>B<tr>2</tr></var><var>C<tr>3</tr></var> <var>B<tr>2</tr></var>
The content of B.txt is as follows
<var>A<tr>1</tr></var> <var>A<tr>1</tr></var> <var>B<tr>2</tr></var> <var>C<tr>3</tr></var> <var>C<tr>3</var>
Similarly, the content of C.txt is as follows
<var>B<tr>0</tr></var> <var>A<tr>1</tr></var> <var>B<tr>2</tr></var> <var>C<tr>3</tr></var> <var>D<tr>4</tr></var>
But the content of D.txt has changed a bit
<var>C<tr>3</tr></var> <var>D<tr>4</tr></var> <var>E<tr>5</tr>
</var>var>F<tr>6</tr></var> <var>E<tr>5</tr></var>
Pay attention to the black part
E.txt
<var>D<tr>4</tr></var> <var>D<tr>4</tr></var> <var>E<tr>5</tr> </var>var>F<tr>6</tr></var> <var>F<tr>6</tr></var>
F.txt
<var>E<tr>5</tr></var> <var>D<tr>4</tr></var> <var>E<tr>5</tr> </var>var>F<tr>6</tr></var> <var>G<tr>7</tr></var>
It can be seen that the black part of A.txt and B.txt, C.txt is ABC The black part of D.txt and E.txt, F.txt is DEF
Red is the previous file name Blue is the next file name The number is the serial number after sorting the file names by name
Only the first and the last are special
Assume Z.txt is the last file, and its content is as follows
<var>Y<tr>25</tr></var> <var>X<tr>24</tr></var><var>Y<tr>25</tr></var> <var>Z<tr>26</tr></var>
The content of B.txt is as follows
<var>A</var> <var>B</var> <var>C</var>
The content of C.txt is as follows
<var>B</var> <var>C</var> <var>D</var>
The content of D.txt is as follows
<var>C</var> <var>D</var> <var>E</var>
The content of E.txt is as follows
<var>C</var> <var>D</var> <var>E</var>
Please pay attention to the part in blue. Except for the first and the last, the text file name is in the middle. The left is the previous one after sorting by name, right is the next one after sorting by name. Except for the first and the last, the following code can already be displayed
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b /a-d *.*^|find /i /v "%~nx0"') do (
set str2=!str1!
set str1=!var!
set var=%%~ni
if defined str2 (
if not defined var1 (
set "var1=!str2!"
>"!str2!.txt" echo ^^^<var^^^>!str2!^^^</var^^^> ^^^<var^^^>!str1!^^^</var^^^> ^^^<var^^^>%%~ni^^^</var^^^>
) else (
>"!str2!.txt" echo ^^^<var^^^>!var1!^^^</var^^^> ^^^<var^^^>!str2!^^^</var^^^> ^^^<var^^^>!str1!^^^</var^^^>
set "var1=!str2!"
set "var2=!var1!"
)))
>"!str1!.txt" echo ^^^<var^^^>!str2!^^^</var^^^> ^^^<var^^^>!str1!^^^</var^^^> ^^^<var^^^>!var!^^^</var^^^>
>"!var!.txt" echo ^^^<var^^^>!str2!^^^</var^^^> ^^^<var^^^>!str1!^^^</var^^^> ^^^<var^^^>!var!^^^</var^^^>
pauseNow the little brother wants to modify the output contentLet A.txt be the first file, and the content is <var>A<tr>1</tr></var> <var>B<tr>2</tr></var><var>C<tr>3</tr></var> <var>B<tr>2</tr></var>
The content of B.txt is as follows
<var>A<tr>1</tr></var> <var>A<tr>1</tr></var> <var>B<tr>2</tr></var> <var>C<tr>3</tr></var> <var>C<tr>3</var>
Similarly, the content of C.txt is as follows
<var>B<tr>0</tr></var> <var>A<tr>1</tr></var> <var>B<tr>2</tr></var> <var>C<tr>3</tr></var> <var>D<tr>4</tr></var>
But the content of D.txt has changed a bit
<var>C<tr>3</tr></var> <var>D<tr>4</tr></var> <var>E<tr>5</tr>
</var>var>F<tr>6</tr></var> <var>E<tr>5</tr></var>
Pay attention to the black part
E.txt
<var>D<tr>4</tr></var> <var>D<tr>4</tr></var> <var>E<tr>5</tr> </var>var>F<tr>6</tr></var> <var>F<tr>6</tr></var>
F.txt
<var>E<tr>5</tr></var> <var>D<tr>4</tr></var> <var>E<tr>5</tr> </var>var>F<tr>6</tr></var> <var>G<tr>7</tr></var>
It can be seen that the black part of A.txt and B.txt, C.txt is ABC The black part of D.txt and E.txt, F.txt is DEF
Red is the previous file name Blue is the next file name The number is the serial number after sorting the file names by name
Only the first and the last are special
Assume Z.txt is the last file, and its content is as follows
<var>Y<tr>25</tr></var> <var>X<tr>24</tr></var><var>Y<tr>25</tr></var> <var>Z<tr>26</tr></var>


