Batch change file names in Windows

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.