中国DOS联盟论坛

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-09 09:12
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » [Solved帖] About the renaming algorithm of ACDSee
Printable Version  2,537 / 21
Floor1 obsolete Posted 2008-07-28 20:59
初级用户 Posts 72 Credits 192
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 ]
Floor2 obsolete Posted 2008-07-28 21:01
初级用户 Posts 72 Credits 192
The program might be rather wordy. If it's troublesome to write, just mention the idea. Thanks!
Floor3 523066680 Posted 2008-07-28 21:25
银牌会员 Posts 1,133 Credits 2,362
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 ]
Floor4 obsolete Posted 2008-07-28 21:38
初级用户 Posts 72 Credits 192
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
Floor5 523066680 Posted 2008-07-28 21:45
银牌会员 Posts 1,133 Credits 2,362
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 ]
Floor6 obsolete Posted 2008-07-28 22:49
初级用户 Posts 72 Credits 192
The following code is very inefficient, let's post it first



[ Last edited by obsolete on 2008-7-28 at 11:20 PM ]
Floor7 obsolete Posted 2008-07-28 23:03
初级用户 Posts 72 Credits 192
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
Floor8 523066680 Posted 2008-07-29 10:12
银牌会员 Posts 1,133 Credits 2,362
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……)
Floor9 obsolete Posted 2008-07-29 22:03
初级用户 Posts 72 Credits 192
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:


[ Last edited by obsolete on 2008-7-30 at 10:05 PM ]
Floor10 obsolete Posted 2008-07-29 22:04
初级用户 Posts 72 Credits 192
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 ]
Floor11 523066680 Posted 2008-07-30 09:49
银牌会员 Posts 1,133 Credits 2,362
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 ]
Floor12 obsolete Posted 2008-07-30 12:43
初级用户 Posts 72 Credits 192
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.
Floor13 obsolete Posted 2008-07-30 12:47
初级用户 Posts 72 Credits 192
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.
Floor14 obsolete Posted 2008-07-30 22:41
初级用户 Posts 72 Credits 192
Please help everyone, there is only one last call and set left


[ Last edited by obsolete on 2008-7-30 at 10:50 PM ]
Floor15 bat-zw Posted 2008-07-30 22:49
金牌会员 Posts 1,276 Credits 3,105
A very simple rename program is made to be like天书, the original poster should not lose the larger point for the small matter!!!
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023