I spent more than half a day checking a lot of information and completed it with the help of a colleague,
When I checked the information, I found that the help provided by windows was useful.
The program code is as follows:
@ Echo off & setlocal enabledelayedexpansion
@ REM ************************************** **************************************** ***
@ REM *** use the following code to name the. txt file in the same directory as the program ****
@ REM *** the length of the original file must be 13(package .txt). The new file name is to remove the first three digits of the original file ****
@ REM *** example: the original file name is 000000100.txt, and the new name is 000100.txt ****
@ REM ************************************** **************************************** ***
@ REM pull the TXT file list and put it in a temporary file
DIR/B ^ | find "* TXT"> 1. Temp
Set oraf =
Set newf =
Set sta =
Echo ===================================================== ====================================
Echo ora file ^ | new file ^ | status
Echo ===================================================== ====================================
@ REM cyclically retrieve data from temporary files
For/F "EOL = # tokens = 1, 2 * delims = \ n" % I in (1. Temp) Do (
Set oraf = % I
@ REM captures the old file name and obtains the new file name.
Set newf =! Oraf :~ 3, 10!
@ REM judgment on the existence of new and old files
If exist! Oraf! (If not exist! Newf! (Set sta = OK) else (set sta = new file is exist! )
) Else (set sta = ora file is not exist! )
If! Sta! = OK (
@ REM rename using the Ren command. If an error occurs, will the error message be returned? 2. Temp File
Ren! Oraf! ! Newf! > 2. Temp
If not exist! Oraf! (If exist! Newf! (Set sta = sucess) else (set sta = Error ))
Else (set sta = Error)
)
Echo! Oraf! ^ |! Newf! ^ |! Sta!
@ REM if an error occurs, output the error message to the console.
If exist 2. Temp (
Type 2. Temp
Del 2. Temp
)
Echo ----------------------------------------------------------------------
)
Del 1. Temp