China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 17:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » It can also be calculated without using variable delay [setlocal enableDelayedExpansion] View 4,770 Replies 49
Floor 31 Posted 2008-06-25 22:39 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
I set up a quick input in EditPlus!

Nothing more to say, it's hard to find a kindred spirit!
Floor 32 Posted 2008-06-25 22:42 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
I've seen the command `ping/n 1 127.1` several times. I know the original meaning of this command, but what role does it play in code like this? Can you explain it to a newbie like me?

Thanks!
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 33 Posted 2008-06-25 22:43 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-6-25 10:38 PM:
It gets a bit chaotic when there are too many people
Plus there are a few who like to edit posts
After reading for a while, the train of thought gets disconnected

Now let's sort it out
ppdos initially just wanted to simplify the LZ's code
Then raised the helplessness...

My initial view has realized the mistake, basically unified the above - floor view,
But I think the abbreviated way of ppdos is incorrect
Floor 34 Posted 2008-06-25 22:44 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-6-25 10:39 PM:

Nothing to say, hard to find bosom friends啊

Haha, hard to find bosom friends, there are actually people with the same interest
Floor 35 Posted 2008-06-25 22:47 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by quya at 2008-6-25 10:42 PM:
Several times I saw "ping/n 1 127.1", I know the original meaning of this command, but what role does it play in code like this? Can you explain it to me, a novice.

Thanks!

Search the forum for posts about batch processing runtime delay aspects
Floor 36 Posted 2008-06-25 22:51 ·  法国
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
Regarding the code condensed into one line Personally speaking It is to be able to test directly in the DOS command line more conveniently Personally, I think it is necessary The test program is not redundant (just I'm lazy and don't want to create a batch file if it can be written in one line)
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃.
Floor 37 Posted 2008-06-25 22:51 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Originally posted by quya at 2008-6-25 10:42 PM:
I have seen the command "ping/n 1 127.1" several times. I know the original meaning of this command, but what role does it play in code like this? Could you explain it to this novice?

Thanks!

Read this post carefully
http://www.cn-dos.net/forum/viewthread.php?tid=8905#pid54227
Floor 38 Posted 2008-06-25 23:19 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Just got poisoned just now, don't know which hateful guy did it. Very depressed.

Another thing, is EditPlus good? There are such good things originally. Used to using Notepad, but it's tiring. Need to change. Download one first.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 39 Posted 2008-06-26 10:11 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by wxcute at 2008-6-25 11:19 PM:
Just got poisoned just now, don't know which hateful guy did it. Very depressed.

Also, is EditPlus good? There are such good things. Used to using Notepad, but it's tiring. Need to change. Download one first.



If everyone gets poisoned later and the antivirus software can't kill it, you can find me.

My old-fashioned batch processing may not work, but my ability to manually remove viruses is unparalleled in the world.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 40 Posted 2008-06-26 10:35 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Shrink into one line to test directly in the command line without displaying the set/a part:
echo off&(for /f %i in ('dir /b') do set /a n+=1 >nul)&call echo There are %n% files(folders) in the directory&echo on
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
PPdos +8 2008-06-27 01:44
Floor 41 Posted 2008-06-26 10:55 ·  中国 广东 深圳 电信
初级用户
★★
Credits 160
Posts 82
Joined 2007-05-14 14:55
19-year member
UID 88494
Gender Male
Status Offline
Learning
Floor 42 Posted 2008-06-26 13:58 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
It seems that everyone lacks thorough practical spirit!

After discussing for so long, only after testing was it discovered that there are major problems in ppdos and the simplified code of zh159. Because all their codes can't stand the test of multiple runs.

The result of the first run is correct, for example, it's 7. But the result of the second run is wrong. It should be 14, but it's still 7. The third time is still wrong. It should be 21, but it's 14.

That is to say, in the environment where setlocal is not set, the environment variables will increase with the number of runs. But what is called and echoed out is always the result before the for execution. Unless the variable called and echoed is empty before this code runs.

The final conclusion is that it's impossible to completely replace echo!var! with call echo %var% in the connection statement

So the final argument I showed in the middle of building 26 is wrong.

Of course, this doesn't affect the view I mentioned in building 30. for+call can completely replace for+delay

As for the code in building 40, in addition to the common problems mentioned above, the idea also takes a detour. To not display set /a, only a @ mark is needed. There's no need to bring out the big gun of echo off.

(for /f %i in ('dir /b') do @set /a n+=1 >nul)&call echo There are %n% under the directory

But I still declare that this kind of abbreviation is very meaningless. Execute for first and then echo %n%, which is simple and clear, and won't have the above problems I mentioned. Why bother!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
plp626 +15 2008-06-27 23:59
Floor 43 Posted 2008-06-26 15:21 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-6-26 01:58 PM:
It seems that everyone lacks the spirit of thorough practice!

After discussing for so long
Only after testing did we discover the major problems of ppdos and the simplified code of zh159
Because all their codes cannot withstand multiple runs...

That's right, simplifying the code is wrong, which is just like echoing once after a for loop is completed
And the code of the original poster can indeed replace the delayed variable
You can take a look at the code in my reply at floor 27. That call and the original poster's call are completely two different usages
Floor 44 Posted 2008-06-26 16:17 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Indeed, I forgot to use @ before set/a.

1. When using in the command line, if you don't clear the variable, the result next time will definitely increase, and you shouldn't be unaware of this!
2. When using in the command line, if there is simply a for followed by an echo, that's two commands entered (first enter the for and press Enter, then enter echo).

PS: It's best not to use call jump if possible, as it has a certain impact on efficiency.
Floor 45 Posted 2008-06-26 18:53 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Just a discussion about variable delay became so intense. I feel the code the original poster provided isn't anything new; I often use it when writing "subroutines".

But I have an off - topic comment: The example the original poster gave doesn't need to use both for and set (I like using batch scripts in the command line and like the casual feeling).

::Number of files
dir/a-d/b|find /c /v ""
::Number of directories
dir/ad/b|find /c /v ""
::Number of files and directories
dir/a-d|findstr/bc:" "
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
quya +4 2008-06-26 19:42
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Forum Jump: