![]() |
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-07 12:55 |
48,040 topics / 350,125 posts / today 0 new / 48,252 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Batch rename "*.txt" files in the same directory with a batch file |
| Printable Version 3,962 / 17 |
| Floor16 wxcute | Posted 2008-02-13 00:43 |
| 中级用户 Posts 211 Credits 458 | |
|
Oh, this. It's for printing.
The printer recognizes three or more "-" symbols as the connector, and the number after that is the number of copies to print. For example: a---3.txt means print this file in 3 copies. Some people say: "Why make it so troublesome? Just click print three copies directly." Yeah, that's fine if there's only one, but if there are many it won't do, so I have to process the documents first, then drag them into the corresponding folder. For example, if I want three copies, I put them into the folder for printing three copies. (And some documents might need two copies today, but four tomorrow, so changing them back and forth is really troublesome.) If I had to rename them one by one, wouldn't that be exhausting? So I came here to ask for help, but the answers I got were not very satisfying, so I started writing it myself, learning and improving as I went. Yesterday I finally wrote one that's not bad, hehe. I see you're also very active on the forum, let's be friends. I've already added you ^_^ |
|
| Floor17 terse | Posted 2008-02-13 12:49 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
The second FOR doesn't need DIR anymore
@echo off for /f "tokens=*" %%i in ('dir /b /a-d *.txt') do call :lp "%%~ni" pause goto :eof :lp set n= setlocal EnableDelayedExpansion for /f "tokens=1* delims=-" %%i in ("%~1") do ( set fils=%%i set fils1=!fils!---3.txt if "%~1.txt" == "!fils1!" goto :eof if exist "!fils1!" ( :rn set /a n+=1 set fils1=!fils!!n!---3.txt if exist "!fils1!" goto rn ) ) ren "%~1.txt" "!fils1!" [ Last edited by terse on 2008-2-13 at 12:54 PM ] |
|
| Floor18 wxcute | Posted 2008-02-14 00:52 |
| 中级用户 Posts 211 Credits 458 | |
|
Awesome, much simpler than mine. Thanks.
I like your signature; looks like I should write one too. |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |