Get the App
SLTechnology News&Howtos  ›  Development  › 

How to rename a file numerically with a batch implementation

Shulou Source: shulou.com Published: 2022-06-03 08:37:57 09月27日 Update

This article will explain in detail how to use batch processing to rename files digitally. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Request:

1. The order of a.txt content cannot be changed.

2. Rename all jpg files in the current directory in the form of serial numbers, such as: from 1mai 16

3. If there are 16 files, they must be renamed to 1-16. Serial numbers after 16 are not allowed.

A.txt content:

The code is as follows:

2.jpg

1.jpg

A.jpg

5ww.jpg

C.jpg

F.jpg

Rty.jpg

3.jpg

11.jpg

B.jpg

6.jpg

E.jpg

8.jpg

111.jpg

7.jpg

30.jpg

The content in a.txt is actually a list of jpg files under the current folder.

Requires that all jpg files in the current folder be renamed in the form of serial numbers.

However, you can only get the file names of all jpg in the current folder from a.txt.

Renaming a file with a sequence number has many pitfalls, but if you use commands such as dir or for to get the file name, the order of acquisition will be regular, resulting in some problems that can not be reflected.

The code is as follows:

@ echo on

Setlocal enabledelayedexpansion

Set nasty 0

Set n1mm 0

For / f "tokens=*" an in (a.txt) do (

Set / a naughty 1

Ren a tanning.jpg

)

: loop

Set / a N1 room1

Ren t%n1%.jpg% n1%.jpg&&goto: loop

Exit

The second method

It seems that it could be easier.

The code is as follows:

@ echo off

Ren * .jpg t*.jpg

Setlocal enabledelayedexpansion

For / f "delims=" an in ('dir/b "t*.jpg"') do (

Set str=%%a&set stranded struts 1!

Ren "a"! str!"

)

Pause

On "how to use batch implementation to rename files digitally" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: File content serial number code folder article number form file name more good practical sequence command that is article method order directory knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia macOS Redmi vpn