中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 13:03
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » [Closed] How to batch rename files?
Printable Version  2,901 / 9
Floor1 23112656 Posted 2008-07-28 02:26
中级用户 Posts 99 Credits 220
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 ]
Floor2 pusofalse Posted 2008-07-28 05:20
银牌会员 Posts 646 Credits 1,604
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
)
Floor3 523066680 Posted 2008-07-28 08:49
银牌会员 Posts 1,133 Credits 2,362
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 ]
Floor4 23112656 Posted 2008-07-30 23:12
中级用户 Posts 99 Credits 220
Hehe```Thanks```Actually I think going the long way is the shortcut to becoming an expert ah`
Floor5 23112656 Posted 2008-07-30 23:31
中级用户 Posts 99 Credits 220
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
Floor6 pusofalse Posted 2008-07-31 07:51
银牌会员 Posts 646 Credits 1,604
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.
Floor7 studythedos Posted 2008-07-31 08:45
初级用户 Posts 45 Credits 91
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..
Floor8 23112656 Posted 2008-08-01 04:33
中级用户 Posts 99 Credits 220
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?
Floor9 523066680 Posted 2008-08-01 10:40
银牌会员 Posts 1,133 Credits 2,362
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 ]
Floor10 gxfc Posted 2008-11-19 17:00
新手上路 Posts 11 Credits 17
I've learned a lot from the post on the 2nd floor, and I'll also bump up the old thread
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023