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-06-24 09:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original]Batch renaming in 001, 002, 003 format View 3,351 Replies 4
Original Poster Posted 2008-07-21 07:49 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Idea 1:
rem This version of editing if_exist http://hi.baidu.com/523066680
@echo off&setlocal enabledelayedexpansion
set /a i=0,j=0,k=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
if !k! equ 9 (set /a k=0,j+=1) else (set /a k+=1)
if !j! equ 10 (set /a j=0,i+=1)
ren %%a !i!!j!!k!.jpg >nul 2>nul
echo number!i!!j!!k!
)

Idea 2:
rem This version of editing if_exist http://hi.baidu.com/523066680
@echo off&setlocal enabledelayedexpansion
set /a i=0,j=0,k=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
set /a k+=1
if !k! equ 9 (set j=)
if !k! equ 100 (set i=)
ren %%a !i!!j!!k!.jpg >nul 2>nul
echo !i!!j!!k!
)

Idea 3: (slow speed, at that time I didn't know the set command, using the nature of renaming)
rem This version of editing if_exist http://hi.baidu.com/523066680

@echo off
ren *.jpg *.
for %%a in (0 1 2 3 4 5 6 7 8 9) do (
for %%b in (0 1 2 3 4 5 6 7 8 9) do (
for %%c in (0 1 2 3 4 5 6 7 8 9) do (
color %%b%%c
ren *. final-%%a%%b%%c.jpg
if not exist *. cls &color 0b &echo OK!! &pause &exit
)
)
)

Reminded by the third floor: Idea two should be changed to:
@echo off&setlocal enabledelayedexpansion
set /a i=0,j=0,k=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
set /a k+=1
if !k! equ 10 (set j=)
if !k! equ 100 (set i=)
ren %%a !i!!j!!k!.jpg >nul 2>nul
echo !i!!j!!k!
)


[ Last edited by 523066680 on 2008-7-22 at 09:06 AM ]
Floor 2 Posted 2008-07-21 09:14 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
::If there are any deficiencies (those that can be improved), you are welcome to report or correct them
hi.baidu.com/523066680

@echo off
mode con cols=77 lines=12
title A batch processing beginner hi.baidu.com/523066680
color 0b

::======================================================================

echo.
echo.Step 1: Enter the beginning of the new file name here. You can directly press Enter (that is, name it 000 001 002) or (0 1 2)
echo. If you enter a, it will be renamed to a000 a001 a002..... or a0 a1 a2......
echo.
echo.Special symbols ^> ^< ^\ ^/ ^? ^" ^: ^| ^* are not supported. Do not enter spaces after entering the name. This batch processing does not judge.
echo.
set /p no1=Please enter:

::======================================================================

cls
echo.
echo.Step 2: Enter the format of the file to be renamed here
echo.
echo.
echo.Special symbols ^> ^< ^\ ^/ ^? ^" ^: ^| ^* spaces, or directly press Enter. This batch processing does not judge.&echo.
set /p no2=Please enter:
if not exist *.%no2% (cls &echo There is no file in %no2% format, please enter correctly, press any key to exit &pause>nul &exit)
if /i %no2%==bat (cls &echo Renaming bat format files is not supported (this file will be renamed, resulting in....) &pause &exit)
cls

::======================================================================

:Second
cls
echo.When executing, if it shows "There is a duplicate file, or the file is not found", do not close it immediately, wait for execution
echo.
echo.Select mode a: Rename to 000 001 002, limited to 999 files (can be changed)
echo.Select mode b: Rename to 1 2 3 4 5 ...., limited to 10000 files (can be changed)
echo.
set /p action="Enter here:"
if /i "%action%"=="a" (goto :ren1-1)
if /i "%action%"=="b" (goto :ren2-1) else (goto :second)

::======================================================================


:ren1-1
cls
ren *.%no2% *.[%no2%]

for %%a in (0 1 2 3 4 5 6 7 8 9) do (
for %%b in (0 1 2 3 4 5 6 7 8 9) do (
for %%c in (0 1 2 3 4 5 6 7 8 9) do (
color %%b%%c &title %%a%%b%%c.%no2%
echo. %no1%%%a%%b%%c.%no2%
ren *.[%no2%] %no1%%%a%%b%%c.%no2%>nul 2>nul
if not exist *.[%no2%] cls &color 0b &echo OK!! &pause &exit
)
)
)

::=======================================================================

:ren2-1
ren *.%no2% *.[%no2%]
for /l %%a in (1,1,10000) do (
echo. %no1%%%a%no2%
ren *.[%no2%] %no1%%%a.%no2%>nul 2>nul
if not exist *.[%no2%] cls &color 0b &echo OK!! &pause &exit
)
Floor 3 Posted 2008-07-22 05:22 ·  中国 吉林 吉林市 联通
初级用户
Credits 68
Posts 32
Joined 2007-12-09 17:16
18-year member
UID 105152
Gender Male
Status Offline
I'm unable to answer this question. You can provide other topics and I will try my best to help you.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
523066680 +2 2008-07-22 08:58
Floor 4 Posted 2008-07-22 08:54 ·  中国 广东 广州 花都区 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Hmm... This elder brother asked well, because I had doubts but did not delve in, which shows my attitude is wrong.
@echo off&setlocal enabledelayedexpansion
set /a i=0,j=0,k=0
for /l %%a in (1,1,30) do (
set /a k+=1
if !k! gtr 9 (set j=)
if !k! equ 100 (set i=)
ren %%a !i!!j!!k!.jpg >nul 2>nul
echo !i!!j!!k!
)
pause

Answer:
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030

No mistake
====================my god!!!==================

Thank you, I found that there was an error in my second idea, so I will give you points to show gratitude, and this post has been up for a day and only you replied, so grateful.

[ Last edited by 523066680 on 2008-7-22 at 09:07 AM ]
Floor 5 Posted 2008-10-02 16:28 ·  中国 广东 佛山 电信
初级用户
★★
Credits 193
Posts 98
Joined 2007-01-17 11:56
19-year member
UID 76803
Gender Male
Status Offline
这家伙很聪明 什么都没留下
Forum Jump: