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-12 06:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Built) Batch rename files View 1,985 Replies 4
Original Poster Posted 2005-08-27 17:43 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 168
Posts 85
Joined 2005-08-26 00:19
20-year member
UID 41941
Gender Male
Status Offline
My system is XP. I want to do such a thing in the "Command Prompt"

In my D:\pic directory, there are 100 *.jpg pictures (file names have different lengths and no unified format). I want to rename them to a unified format such as abc1.jpg abc2.jpg abc3.jpg abc100.jpg

Ask the batch processing experts how to achieve this, thank you in advance!

[ Last edited by willsort on 2005-8-28 at 14:30 ]
Floor 2 Posted 2005-08-27 22:19 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
In fact, the owner's problem can be easily achieved using third-party renaming software (such as Tuoba Renamer), or even using Windows Explorer and ACDSee, etc. But since the owner requires using the command line, the following are several methods.

For a while, I can't think of how to do it without using third-party tools, so first give a method using the third-party tool lmod:

@echo off
lmod > nul
dir /b *.* | lmod /L* ren "" abc.jpg > %temp%\temp.bat
call %temp%\temp.bat
del %temp%\temp.bat


When writing this batch processing, I suddenly thought of a method without using third-party tools:

@echo off
:: It is required that your file name must contain the jpg extension
dir /b | find /n /i "jpg" > %temp%\temp.txt
for /f "delims= tokens=1,*" %%i in (%temp%\temp.txt) do ren "%%j" abc%%i.jpg && echo Rename "%%j" to "abc%%i.jpg"
del %temp%\temp.txt
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-08-28 10:51 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 168
Posts 85
Joined 2005-08-26 00:19
20-year member
UID 41941
Gender Male
Status Offline
Thank you very much for Climbing's answer. I know that ACDSEE can be easily used to get it done, but I just want to learn batch processing well!
Floor 4 Posted 2005-08-28 14:32 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
To learn batch processing well, you need to work hard to improve your level by solving problems. Simply relying on others to give you solutions to learn from, I feel you won't learn anything useful.

The application of computers is nothing but the amount of experience accumulated.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2009-08-05 05:48 ·  中国 四川 德阳 绵竹市 电信
中级用户
★★
Credits 274
Posts 192
Joined 2009-01-07 21:09
17-year member
UID 136069
Gender Male
Status Offline
Computers are just constantly summarizing experiences. Thanks for the guidance from Lone Ranger.
Forum Jump: