China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 16:00
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to batch rename files? View 2,903 Replies 9
Original Poster Posted 2008-07-28 02:26 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
I'll first state the situation. There are N JPG - format pictures in my computer, and the names of the pictures are all jumbled. Is there a way to rename these pictures starting from 1 and renaming them in sequence? For example: 1.jpg, 2.jpg, 3.jpg. I've tried many methods but still can't make it work. I think I should use the FOR /L command, but no matter how I change it, I can only rename one file. I'm really depressed. Please, all you experts, give me some advice.

Finally, please trouble all the experts to explain the detailed code. Thanks again.

[ Last edited by HAT on 2008 - 11 - 19 at 17:08 ]
Floor 2 Posted 2008-07-28 05:20 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
There have been many such problems, exactly the same as yours.
http://www.cn-dos.net/forum/viewthread.php?tid=37611&fpage=1&highlight=%E6%89%B9%E9%87%8F%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E5%90%8D

for %%a in (*.jpg) do (
set/a n+=1
call ren "%%a" %%n%%.jpg
)
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 3 Posted 2008-07-28 08:49 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Short, super short... Speechless... Helpless... Envious...

The code above is already concise to the point where there's not much to explain. If there is, it's the call part... This is a very good example. The poster should master the skills! (Depressed... I don't know this... The poster is really lucky, just came and has something to learn)

Paste one of mine, which is very inefficient. It was written when I just started: (Without using the set command)
ren *.jpg *.
for /l %%a in (1,1,10000) do (
ren *. a-%%a.jpg 2>nul
if not exist *. exit
)
Explanation: Rename all jpg files to format
Then the for /l %%a from 1 to 10000
f1 -- Rename *. to 1.jpg Because of the system error, so only one 1.jpg can be renamed
f2 -- Rename *. to 2.jpg Because it's ren *. so the previous 1.jpg won't be changed to 2.jpg
And still extract one 2.jpg from the remaining to achieve the effect of renaming one by one.
f3 f4 and so on
This method is not supported for everyone to use. It's purely going the long way... Having nothing better to do, obviously there's a精华 post, but still insist on writing one of my own.

[ Last edited by 523066680 on 2008-7-31 at 03:06 PM ]
Floor 4 Posted 2008-07-30 23:12 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
Hehe```Thanks```Actually I think going the long way is the shortcut to becoming an expert ah`
Floor 5 Posted 2008-07-30 23:31 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
But why aren't the numbers arranged in order when using the code from floor 2? To be precise, the numbers start to be arranged correctly only after reaching 100. The numbers before 100 are all renamed in a jumping manner
Floor 6 Posted 2008-07-31 07:51 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
It's not about renaming by jumping, but the different arrangement order. You right - click and arrange the names. It runs normally on my computer.
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 7 Posted 2008-07-31 08:45 ·  中国 河南 南阳 联通
初级用户
Credits 91
Posts 45
Joined 2007-03-14 07:04
19-year member
UID 81689
Gender Male
Status Offline
I saw a batch - modified one before, which first deleted to the recycle bin, and thought it was quite troublesome. It turns out there is such a simple one here. Learned it..
Floor 8 Posted 2008-08-01 04:33 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
Originally posted by pusofalse at 2008-7-31 07:51 AM:
It's not renaming by jumping, but the order of arrangement is different. You can right-click and sort by name.
It runs normally on my computer.



I have sorted it, but it's still as I said. So I created 2 batches. After executing one, the arrangement is abnormal, and then executing the second one is fine. What's the problem in between? Is it related to delay?
Floor 9 Posted 2008-08-01 10:40 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Maybe...

Try changing for %%a in (*.jpg) do (
to  for /f "tokens=*" %%a in ('dir *.jpg') do (

I think it's possible that after renaming, the files that have already been renamed are still being read by for, causing the same part of the files to be renamed repeatedly

But when I tested here, there was no problem

Welcome to refer to this post: http://www.cn-dos.net/forum/viewthread.php?tid=41846&fpage=2

There are essential posts of batch processing in the top area of the batch processing section of the forum
Support the building to download, read it carefully, and gain a lot

[ Last edited by 523066680 on 2008-8-1 at 10:54 AM ]
Floor 10 Posted 2008-11-19 17:00 ·  中国 山西 阳泉 联通
新手上路
Credits 17
Posts 11
Joined 2006-10-22 13:10
19-year member
UID 67721
Gender Male
Status Offline
I've learned a lot from the post on the 2nd floor, and I'll also bump up the old thread
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
yishanju -4 2008-11-19 18:49
Forum Jump: