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-09 07:00
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Still can't think of a solution after reading the related posts (renaming) View 769 Replies 5
Original Poster Posted 2008-07-27 10:51 ·  中国 贵州 贵阳 电信
新手上路
Credits 6
Posts 3
Joined 2008-07-25 17:25
18-year member
UID 122097
Gender Male
Status Offline
Floor 2 Posted 2008-07-27 12:22 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
First assume that all the jpg files and name.txt are placed in the d:\pic folder. For actual use, the OP can modify it himself:

@echo off&setlocal enabledelayedexpansion
set "n=-1"
for /f "delims=" %%i in ('dir /s /a-d /b d:\pic\*.jpg') do (
set /a n+=1&call :lp
ren "%%i" !str!
)
echo All done.&pause>nul&goto :eof
:lp
if %n% equ 0 (set "m=") else (set "m=skip=%n%")
for /f "%m% dielims=" %%i in (name.txt) do set "str=%%i"&goto :eof
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-07-27 12:41 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
I wrote one, but I don't know whether duplicate filenames already exist. Back up first, then try it.

@echo off
for /f "tokens=*" %%i in ('dir /b /s /a-d *.jpg') do call:lp "%%i"
:lp
for /f "usebackq tokens=*" %%j in ("name.txt") do (
if not defined %%j set %%j=a&ren %1 "%%j"&goto :eof)
pause
简单!简单!再简单!
Floor 4 Posted 2008-07-27 14:14 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
After coming to the DOS forum, I've found my head getting a lot bigger... Depressing, extremely depressing...
Every time I see this kind of question, I break out in a cold sweat...
Floor 5 Posted 2008-07-27 14:33 ·  中国 贵州 贵阳 电信
新手上路
Credits 6
Posts 3
Joined 2008-07-25 17:25
18-year member
UID 122097
Gender Male
Status Offline
Originally posted by terse at 2008-7-27 12:41 PM:
I wrote one, but I don't know whether duplicate filenames already exist. Back up first, then try it.

@echo off
for /f "tokens=*" %%i in ('dir /b /s /a-d *.jpg') do call:lp "%%i"
:lp
for /f "useb ...

Thanks! The problem is solved! Could you help explain what each line means???
Floor 6 Posted 2008-07-27 14:34 ·  中国 贵州 贵阳 电信
新手上路
Credits 6
Posts 3
Joined 2008-07-25 17:25
18-year member
UID 122097
Gender Male
Status Offline
Originally posted by bat-zw at 2008-7-27 12:22 PM:
First assume that all the jpg files and name.txt are placed in the d:\pic folder. For actual use, the OP can modify it himself:

@echo off&setlocal enabledelayedexpansion
set "n=-1"
for /f "d ...

It says command syntax error, but thank you all the same!
Forum Jump: