中国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-02 03:36
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » [Recommended][Discussion] K&H home - NT/Win2k scripting
Printable Version  1,195 / 7
Floor1 bagpipe Posted 2006-08-19 14:12
银牌会员 Posts 425 Credits 1,144 From 北京
Floor2 electronixtar Posted 2006-08-19 14:32
铂金会员 Posts 2,672 Credits 7,493
A post that's 34 screens long~~ sigh~~
Floor3 220110 Posted 2006-08-20 17:59
荣誉版主 Posts 313 Credits 718
bagpipe, I don't know whether you noticed it, but I found there's a trick in this:



:exec
%*
goto :eof




But I still can't quite make sense of it for now. Heh. We'll have to ask willsort and the other three moderators for a deeper explanation.


Also, to willsort:
I think the following code isn't much less efficient than what we discussed before here:a question about randomly getting file names


@echo off
setlocal
set _i=0
for %%a in (*) do (
call :exec set /a _i+=1
call :exec echo %%_i%%: %%a
)
endlocal
goto :eof

:exec
%*
goto :eof

goto :eof




[ Last edited by 220110 on 2006-8-20 at 21:36 ]
Floor4 doscc Posted 2006-08-21 02:33
中级用户 Posts 93 Credits 256 From 广东
Re: brother bagpipe
A lot of very good batch files! Your post is really nice!

Re: brother 220110


Floor5 bagpipe Posted 2006-08-21 08:59
银牌会员 Posts 425 Credits 1,144 From 北京
As long as someone reads it, I'm fully satisfied........... after all, it's a post in English, so not many people care about it
Floor6 willsort Posted 2006-08-22 02:09
元老会员 Posts 1,512 Credits 4,432

───────────────── Moderator Record ─────────────────
Executed by: Will Sort
Action: modified title - 22699 - Let's discuss and study this batch file together
Penalty: deducted the 6 credits awarded for posting this topic, and deducted an additional 2 credits as a penalty for a title rule violation
───────────────── Moderator Record ─────────────────

Re bagpipe:

It's necessary to remind you that the titles of several of your topics have been rather vague. In the past, no action was taken in view of the relatively high quality of the content, and I hope similar problems will not appear again.

Also, please note that for reposted articles you must indicate the original link so readers can check it. Generally there is no need to combine and repost two articles together; if there really is such a need, please add the necessary markers where the texts join.

[ Last edited by willsort on 2006-8-22 at 02:14 ]
Floor7 willsort Posted 2006-08-22 02:47
元老会员 Posts 1,512 Credits 4,432
Re 220110:

As brother doscc said, %* represents the entire command-line argument list starting from %1.

The function of the :exec section should be to execute the passed-in command-line argument list once again as a new independent command line.

The difference between call :exec commands ... and call commands is that the former calls a label section inside the batch file itself, while the latter directly calls internal or external commands.

As for that piece of code, since the functions it implements are not the same, their efficiency is not really comparable.

Re doscc:

>When calling the :exec label, no parameters are being passed

In fact, parameters are being passed, otherwise %* would do nothing at all.

The reason it still works without calling :exec is that call has the characteristic of reconstructing the command-line environment (including the variable environment). Although under xp's cmd, :exec really does seem superfluous, the author's writing environment was NT/2K, which may not have had some of xpcmd's features (for example, delayed variable expansion was not supported before NT4.0(2000)), so a double-call or call :exec calling structure was used.

Also, I added simple comments to the final code in the article command line parameter parsing, as follows:



[ Last edited by willsort on 2006-8-22 at 02:49 ]
Floor8 bagpipe Posted 2006-08-22 08:57
银牌会员 Posts 425 Credits 1,144 From 北京
I really have nothing to say now. I was just about to reach Silver Member, and now this again — have to wait a few more days, sigh
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023