![]() |
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-11 08:39 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Discussion] A vulnerability present in many batch renaming tools |
| Printable Version 2,176 / 9 |
| Floor1 523066680 | Posted 2009-01-10 11:20 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
|
Accidentally discovered a bug that many BatchRen have ~ The dir will sort and list the names, but...
For example, there are 0.jpg and 1.jpg. When renaming 0.jpg to 1.jpg for the first time... it will go wrong. First, talk about the classic @echo off for %%a in (*.jpg) do (set /a n+=1 &call ren %%a %%n%%.jpg) The code is short, but when renaming, many numbers are added some I renamed files from 001-099, and as a result, numbers above 100 appeared, and I couldn't figure it out So I echoed it, and it was depressing. That for sentence can catch the renamed files again into the collection... so advanced a function Advanced list as follows 001.jpg - 1 : : 085.jpg - 85 086.jpg - 86 087.jpg - 87 088.jpg - 88 089.jpg - 89 090.jpg - 90 091.jpg - 91 092.jpg - 92 093.jpg - 93 094.jpg - 94 095.jpg - 95 096.jpg - 96 097.jpg - 97 098.jpg - 98 099.jpg - 99 1.jpg - 100 10.jpg - 101 11.jpg - 102 12.jpg - 103 13.jpg - 104 14.jpg - 105 15.jpg - 106 16.jpg - 107 : : And generally, after renaming once, renaming again will have problems, the numbers are chaotic, repeated contradictions... Changing to for /f "tokens=*" %%a in ('dir *.jpg /b ') do ( will not have the problem of repeatedly renaming the same file ----------------------------------------------------------------------- Continue with the previous problem: dir will sort and list the names, but... For example, there are 0.jpg and 1.jpg. When renaming 0.jpg to 1.jpg for the first time... it will go wrong. Temporary solution is - ren *.jpg *.jpg# Then rename one by one, and there will be no name conflict. When there are many jpg files, there is a slight pause at the beginning. Here's my own code, rough, [ Last edited by 523066680 on 2009-1-14 at 09:39 ] |
|
| Floor2 yishanju | Posted 2009-01-10 11:36 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
After reading it back and forth twice, I still couldn't figure out what it was talking about.
|
|
| Floor3 moniuming | Posted 2009-01-10 11:53 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
I also found this problem before. The first file that was renamed will be renamed again.
|
|
| Floor4 HAT | Posted 2009-01-10 16:04 |
| 版主 Posts 5,017 Credits 9,023 | |
|
It is suggested to add search - friendly keywords in the post title
|
|
| Floor5 everest79 | Posted 2009-01-10 16:23 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
The process of for enumeration and ren listing is both gradual, so there will be such characteristics
|
|
| Floor6 523066680 | Posted 2009-01-14 09:40 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
| Floor7 pkto | Posted 2009-01-14 12:12 |
| 初级用户 Posts 62 Credits 62 | |
|
The building is really careful! Thanks for the reminder! The code is very practical
|
|
| Floor8 netbenton | Posted 2009-01-15 00:53 |
| 银牌会员 Posts 752 Credits 1,916 From 广西 | |
|
::Fast, can modify long filenames
@echo off&setlocal enabledelayedexpansion for /f "tokens=1 delims= " %%a in ('dir *.jpg ^| findstr 个文件') do set n=%%a set /a n=n/10+1 set b=0 for /f "tokens=* delims=" %%a in ('dir /b *.jpg ^| findstr .jpg') do ( set name=000000000!b! set name=!name:~-%n%! ren "%%a" "!name!.jpg" set /a b+=1 ) pause [ Last edited by netbenton on 2009-1-15 at 00:57 ] |
|
| Floor9 samliu | Posted 2009-02-07 17:58 |
| 新手上路 Posts 15 Credits 15 | |
|
I copied a copy of the original poster's source code. Just tried it, only one didn't change the name, which is the picture originally named 14. The others were all changed, even those with mixed numbers and English were fine. But, I can't figure out why the one originally named 14 didn't change. So, I still want to consult the original poster.
|
|
| Floor10 wxcute | Posted 2009-02-07 19:32 |
| 中级用户 Posts 211 Credits 458 | |
|
The first "naked" FOR uses CALL to call the label process, and this problem won't occur.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |