|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『楼 主』:
[结贴]关于ACDSee的重命名算法
使用 LLM 解释/回答一下
比如说设置了模板:Head_???_Body_?_Tail,从1递增到1001,应该产生以下的命名:
Head_001_Body_1_Tail
Head_002_Body_2_Tail
Head_003_Body_3_Tail
...
Head_010_Body_10_Tail
Head_011_Body_11_Tail
...
Head_1000_Body_1000_Tail
Head_1001_Body_1001_Tail
目的不在实用,主要是锻炼一下。模板由用户自定义,模板中可能连续出现多达255个通配符"?",比如???????????Head?????????????Body??Tail?
思考了1天在效率上没有突破,请大家帮忙,谢谢!!
在此感谢bat-zw和523066680的热情帮助
Last edited by obsolete on 2008-7-31 at 10:30 PM ]
For example, if the template is set as Head_???_Body_?_Tail, incrementing from 1 to 1001, the following names should be generated:
Head_001_Body_1_Tail
Head_002_Body_2_Tail
Head_003_Body_3_Tail
...
Head_010_Body_10_Tail
Head_011_Body_11_Tail
...
Head_1000_Body_1000_Tail
Head_1001_Body_1001_Tail
The purpose is not for practical use, mainly to exercise. The template is customized by the user, and there may be up to 255 wildcards "?" in the template, such as???????????Head?????????????Body??Tail?
After thinking for 1 day, there is no breakthrough in efficiency. Please help, thank you!
Thanks to bat-zw and 523066680 for their enthusiastic help here
Last edited by obsolete on 2008-7-31 at 10:30 PM ]
|
|
2008-7-28 20:59 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
程序可能会比较啰嗦,如果写起来麻烦,可以只说一下思路。谢谢!
The program might be rather wordy. If it's troublesome to write, just mention the idea. Thanks!
|
|
2008-7-28 21:01 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
大致符合题意有待改进…… 不过,大家看到这类帖都会比较……
毕竟太多人问批量重命名的事儿了,我觉得题目吸引人很重要。
rem 这一版本的编辑if_exist http://hi.baidu.com/523066680
@echo off&setlocal enabledelayedexpansion
set /a i=0,j=0,k=0,l=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
set /a l+=1
if !l! equ 10 (set k=)
if !l! equ 100 (set j=)
if !l! equ 1000 (set i=)
ren %%a Head_!i!!j!!k!!l!_Body_!l!_Tail.jpg >nul 2>nul
)
=--------------------------以下代码应该能够完全符合-------------------
rem 这一版本的编辑if_exist http://hi.baidu.com/523066680
@echo off&setlocal enabledelayedexpansion
set /a j=0,k=0,l=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
set /a l+=1
if !l! equ 10 (set k=)
if !l! equ 100 (set j=)
ren %%a Head_!j!!k!!l!_Body_!l!_Tail.jpg >nul 2>nul
)
=---------------------------------------------------------------------------
不过在页面浏览的时候,001-099在前面,1000-????在中间
100-999在后面……没办法,电脑是按开头的字符排的……
我一开始看的时候还以为漏了什么。
Last edited by 523066680 on 2008-7-28 at 10:15 PM ]
It is roughly in line with the meaning but needs improvement... However, everyone will be relatively... after all, too many people ask about batch renaming. I think it's important for the title to be attractive.
rem This version is edited with if_exist http://hi.baidu.com/523066680
@echo off&setlocal enabledelayedexpansion
set /a i=0,j=0,k=0,l=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
set /a l+=1
if !l! equ 10 (set k=)
if !l! equ 100 (set j=)
if !l! equ 1000 (set i=)
ren %%a Head_!i!!j!!k!!l!_Body_!l!_Tail.jpg >nul 2>nul
)
=--------------------------The following code should be able to fully conform-------------------
rem This version is edited with if_exist http://hi.baidu.com/523066680
@echo off&setlocal enabledelayedexpansion
set /a j=0,k=0,l=0
for /f "tokens=*" %%a in ('dir *.jpg /b') do (
set /a l+=1
if !l! equ 10 (set k=)
if !l! equ 100 (set j=)
ren %%a Head_!j!!k!!l!_Body_!l!_Tail.jpg >nul 2>nul
)
=---------------------------------------------------------------------------
But when browsing the page, 001-099 are in the front, 1000-???? are in the middle
100-999 are at the back... There's no way, the computer sorts by the leading characters...
I thought something was missing when I first looked at it.
Last edited by 523066680 on 2008-7-28 at 10:15 PM ]
|

综合型编程论坛
我的作品索引 |
|
2008-7-28 21:25 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
谢谢楼上。
效率很高,我一天都没想到这种方法TT,
问题是不够通用,模板是用户自己设的,可能最后这个字符串拼起来会很吃力
Thanks topper.
High efficiency, I didn't think of this method all day TT,
The problem is not universal enough, the template is set by the user himself, maybe the final string splicing will be very difficult
|
|
2008-7-28 21:38 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
觉得好就加加分!那我谢谢你啦!等下改改 ,看能否完全符合题意
以下内容并非代表本人立场
欢迎来到 hat前辈建立的群 61377162
Last edited by 523066680 on 2008-7-28 at 09:52 PM ]
If you think it's good, give some extra points! Then I thank you! I'll modify it later to see if it can fully meet the requirements.
The following content does not represent my position.
Welcome to the group 61377162 established by前辈 hat.
Last edited by 523066680 on 2008-7-28 at 09:52 PM ]
|

综合型编程论坛
我的作品索引 |
|
2008-7-28 21:45 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
下面这段代码效率很低,先贴上来吧
@echo off
setlocal enabledelayedexpansion
set wildchars=?
for /l %%i in (1,1,8) do (
set wildchars=!wildchars!!wildchars!
)
set zeroes=!wildchars:?=0!
set template=?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
set tpl=%template%
for /l %%i in (255,-1,1) do (
set wcs=!wildchars:~0,%%i!
call,set temp=%%tpl:!wcs!=%%
if not "!tpl!"=="!temp!" (set occr=!occr! %%i & set tpl=!temp!)
)
for /l %%a in (1,1,1001) do (
set num=%%a
set str=%zeroes%%%a
set file=%template%
for %%b in (!occr!) do (
set wcs=!wildchars:~0,%%b!
set temp=!num:~%%b!
if defined temp (set n=%%a) else set n=!str:~-%%b!
call,set file=%%file:!wcs!=!n!%%
)
echo !file!
echo.
)
pause
Last edited by obsolete on 2008-7-28 at 11:20 PM ]
The following code is very inefficient, let's post it first
@echo off
setlocal enabledelayedexpansion
set wildchars=?
for /l %%i in (1,1,8) do (
set wildchars=!wildchars!!wildchars!
)
set zeroes=!wildchars:?=0!
set template=?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
set tpl=%template%
for /l %%i in (255,-1,1) do (
set wcs=!wildchars:~0,%%i!
call,set temp=%%tpl:!wcs!=%%
if not "!tpl!"=="!temp!" (set occr=!occr! %%i & set tpl=!temp!)
)
for /l %%a in (1,1,1001) do (
set num=%%a
set str=%zeroes%%%a
set file=%template%
for %%b in (!occr!) do (
set wcs=!wildchars:~0,%%b!
set temp=!num:~%%b!
if defined temp (set n=%%a) else set n=!str:~-%%b!
call,set file=%%file:!wcs!=!n!%%
)
echo !file!
echo.
)
pause
Last edited by obsolete on 2008-7-28 at 11:20 PM ]
|
|
2008-7-28 22:49 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
上面代码在文件名长度不超过255的前提下,最坏情况的模板是:
?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
也就是通配符从1~22都出现了,可以这样近似计算:
x*(x+1)/2 + x-1=255
The worst - case template above, on the premise that the file name length does not exceed 255, is:
?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
That is, wildcards from 1 to 22 all appear. It can be approximately calculated like this:
x*(x+1)/2 + x - 1 = 255
|
|
2008-7-28 23:03 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
汗……不知道你在说啥……数学 批处理……我的娘~
(最讨厌数学了!但是没法,我也爱数学,有爱就有恨……)
Sweat……I don't know what you're talking about……Mathematics Batch processing……Oh my goodness~
(The most hated mathematics! But there's no way, I also love mathematics, there is love there is hate……)
|

综合型编程论坛
我的作品索引 |
|
2008-7-29 10:12 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
6楼算法中最耗时的部分是call,set,算法改进的目的就是去除这个。
改善的算法:
@echo off
setlocal enabledelayedexpansion
set template=?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
set template=!template:?=:?!
set template=!template:?:=/!
set template=!template::=!
set colons=:::::::::
for /l %%a in (1,1,1001) do (
set file=%template%
set n=0
set num=%%a
for /l %%b in (1,1,9) do (
set /a "num=num/10"
if not !num!==0 set /a "n+=1"
)
call,set rep=%%colons:~0,!n!%%%%a
call,set file=%%file:?=!rep!%%
for /l %%i in (1,1,9) do (
set file=!file:/:=!
)
set file=!file:/=0!
set file=!file::=!
echo !file!
echo.
)
pause
Last edited by obsolete on 2008-7-30 at 10:05 PM ]
The most time-consuming part in the algorithm of floor 6 is call and set. The purpose of algorithm improvement is to remove this.
Improved algorithm:
@echo off
setlocal enabledelayedexpansion
set template=?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
set template=!template:?=:?!
set template=!template:?:=/!
set template=!template::=!
set colons=:::::::::
for /l %%a in (1,1,1001) do (
set file=%template%
set n=0
set num=%%a
for /l %%b in (1,1,9) do (
set /a "num=num/10"
if not !num!==0 set /a "n+=1"
)
call,set rep=%%colons:~0,!n!%%%%a
call,set file=%%file:?=!rep!%%
for /l %%i in (1,1,9) do (
set file=!file:/:=!
)
set file=!file:/=0!
set file=!file::=!
echo !file!
echo.
)
pause
Last edited by obsolete on 2008-7-30 at 10:05 PM ]
|
|
2008-7-29 22:03 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
9楼算法还利用了一个前提是:整形的最大值在21亿左右,也就是10位。
超过10位的无法处理(因为for循环不支持)
Last edited by obsolete on 2008-7-29 at 10:08 PM ]
The algorithm on floor 9 also uses a premise that the maximum value of an integer is around 2.1 billion, which is 10 digits. Those exceeding 10 digits cannot be processed (because the for loop does not support it)
Last edited by obsolete on 2008-7-29 at 10:08 PM ]
|
|
2008-7-29 22:04 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
哎就是重命名嘛 要求那么高干什么 ……
我写了一个多选择的重命名批处理
:: 这一版本的编辑if_exist http://hi.baidu.com/523066680
@echo off
:write-geshi
set /p geshi="请输入将被重命名的文件格式,如jpg:"
if not exist *.%geshi% echo.不存在该格式 &goto write-geshi
if "%geshi%"=="" echo.不存在该格式 &goto write-geshi
cls
:write-left
echo.给文件名输入特征部分,输入a-则命名为a-001,a-002……
echo.直接enter则名字直接为序号
echo.不要输入特殊字符
set /p tezheng=":"
:write-lei
set /p lei="选择类型,输入 001 或1 :"
if "%lei%" == "001" (goto :001)
if "%lei%" == "1" (goto :1) else (echo.输入错误 &goto :write-lei)
:001
setlocal enabledelayedexpansion
set /a i=0,j=0,k=0
for /f "tokens=*" %%a in ('dir *.%geshi% /b') do (
set /a k+=1
if !k! equ 10 (set j=)
if !k! equ 100 (set i=)
ren %%a %tezheng%!i!!j!!k!.%geshi% >nul 2>nul
echo !i!!j!!k!
)
echo over! 按任何键继续 &pause>nul &exit
:1
setlocal enabledelayedexpansion
set /a k=0
for /f "tokens=*" %%a in ('dir *.%geshi% /b') do (
set /a k+=1
ren %%a %tezheng%!k!.%geshi%
echo !k!
)
echo over! 按任何键继续 &pause>nul &exit
---------------------------------------------------------------------------------
对于13楼的话,额……都说啦 要求不要那么多嘛……
以上的已经可以有很多变化了
Last edited by 523066680 on 2008-7-30 at 03:06 PM ]
Hey, it's just renaming. Why be so demanding...
I wrote a multi - choice batch for renaming
:: This version is edited for if_exist http://hi.baidu.com/523066680
@echo off
:write - geshi
set /p geshi="Please enter the file format to be renamed, such as jpg:"
if not exist *.%geshi% echo. There is no such format &goto write - geshi
if "%geshi%"=="" echo. There is no such format &goto write - geshi
cls
:write - left
echo. Enter the characteristic part of the file name. Enter a - and it will be named a - 001, a - 002...
echo. Press Enter directly and the name will be the serial number directly
echo. Do not enter special characters
set /p tezheng=":"
:write - lei
set /p lei="Select the type, enter 001 or 1 :"
if "%lei%" == "001" (goto :001)
if "%lei%" == "1" (goto :1) else (echo. Incorrect input &goto :write - lei)
:001
setlocal enabledelayedexpansion
set /a i=0,j=0,k=0
for /f "tokens=*" %%a in ('dir *.%geshi% /b') do (
set /a k+=1
if !k! equ 10 (set j=)
if !k! equ 100 (set i=)
ren %%a %tezheng%!i!!j!!k!.%geshi% >nul 2>nul
echo !i!!j!!k!
)
echo over! Press any key to continue &pause>nul &exit
:1
setlocal enabledelayedexpansion
set /a k=0
for /f "tokens=*" %%a in ('dir *.%geshi% /b') do (
set /a k+=1
ren %%a %tezheng%!k!.%geshi%
echo !k!
)
echo over! Press any key to continue &pause>nul &exit
---------------------------------------------------------------------------------
Regarding the words of the 13th floor, uh... I've already said it. Don't be so demanding...
The above already has many variations
Last edited by 523066680 on 2008 - 7 - 30 at 03:06 PM ]
|

综合型编程论坛
我的作品索引 |
|
2008-7-30 09:49 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
恩我也打算写一个重命名的批处理,主要是想写得通用一些,这样每次要用的时候改几个变量就可以用了,方便。
Well, I also plan to write a batch script for renaming. The main idea is to make it general - purpose so that every time I need to use it, I can just change a few variables, which is convenient.
|
|
2008-7-30 12:43 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
11楼的方法,在一些常见任务中比9楼的要快很多,唯一的缺憾是不够通用,模板变化了得修改程序。
The method on the 11th floor is much faster than the one on the 9th floor in some common tasks. The only shortcoming is that it is not universal; if the template changes, the program needs to be modified.
|
|
2008-7-30 12:47 |
|
|
obsolete
初级用户
 
积分 192
发帖 72
注册 2005-7-31
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
请大家帮帮忙啊,剩下最后一个call,set了
@echo off
setlocal enabledelayedexpansion
set template=?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
set template=!template:?=:?!
set template=!template:?:=/!
set template=!template::=!
for /l %%a in (1,1,1001) do (
set file=%template%
set temp=%%a:::::::::
set rep=!temp:~10!%%a
call,set file=%%file:?=!rep!%%
for /l %%i in (1,1,9) do (
set file=!file:/:=!
)
set file=!file:/=0!
set file=!file::=!
echo !file!
echo.
)
pause
Last edited by obsolete on 2008-7-30 at 10:50 PM ]
Please help everyone, there is only one last call and set left
@echo off
setlocal enabledelayedexpansion
set template=?a??b???c????d?????e??????f???????g????????h?????????i??????????j???????????k????????????l?????????????m??????????????n???????????????o????????????????p?????????????????q??????????????????r???????????????????s????????????????????t?????????????????????u??????????????????????
set template=!template:?=:?!
set template=!template:?:=/!
set template=!template::=!
for /l %%a in (1,1,1001) do (
set file=%template%
set temp=%%a:::::::::
set rep=!temp:~10!%%a
call,set file=%%file:?=!rep!%%
for /l %%i in (1,1,9) do (
set file=!file:/:=!
)
set file=!file:/=0!
set file=!file::=!
echo !file!
echo.
)
pause
Last edited by obsolete on 2008-7-30 at 10:50 PM ]
|
|
2008-7-30 22:41 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
一个很简单的重命名程序搞得像天书,楼主不要因小失大啊!!!
A very simple rename program is made to be like天书, the original poster should not lose the larger point for the small matter!!!
|

批处理之家新域名:www.bathome.net |
|
2008-7-30 22:49 |
|