中国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-08 18:45
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Batch calendar
Printable Version  4,255 / 23
Floor1 huzixuan Posted 2007-02-17 00:00
高级用户 Posts 219 Credits 537 From 芜湖
It's almost New Year, little brother presents the calendar. If there are better, more convenient and simpler methods, please discuss.
There are any improper places in the code, everyone is welcome to criticize............
Wish: Happy New Year, all the best. Good luck in everything in the Year of the Pig!!


[ Last edited by huzixuan on 2007-2-21 at 10:49 PM ]
Floor2 jmz573515 Posted 2007-02-17 00:12
银牌会员 Posts 464 Credits 1,212
Adding the year would be even more perfect...
Floor3 huzixuan Posted 2007-02-17 00:17
高级用户 Posts 219 Credits 537 From 芜湖
Because I am still in the stage of learning to fly and cannot yet achieve more complex functions, so I still need the help of brothers to complete it.
Floor4 slore Posted 2007-02-17 00:42
铂金会员 Posts 2,478 Credits 5,212
for %%b in (31,28,31,30,31,30,31,31,30,31,30,31) do (

Is February always 28 days?
Floor5 huzixuan Posted 2007-02-17 00:59
高级用户 Posts 219 Credits 537 From 芜湖
Isn't it from 2007;) And I really want to write something that works for many years, but I don't know how....

[ Last edited by huzixuan on 2007-2-17 at 01:00 AM ]
Floor6 xycoordinate Posted 2007-02-17 01:33
中级用户 Posts 228 Credits 493 From 安徽
In batch scripting, the exclamation marks are used for delayed expansion. When delayed expansion is enabled, variables within loops or conditional blocks can be accessed correctly as their values change during execution. Without delayed expansion, the old value of the variable would be used instead. So in this context, the exclamation marks are related to enabling and using delayed variable expansion in the batch code.
Floor7 huzixuan Posted 2007-02-17 04:19
高级用户 Posts 219 Credits 537 From 芜湖
Oh, my poor little calendar has sunk to the bottom of the sea without getting more people's encouragement.....
Floor8 gne3 Posted 2007-02-17 05:20
高级用户 Posts 252 Credits 526
Floor9 huzixuan Posted 2007-02-17 06:16
高级用户 Posts 219 Credits 537 From 芜湖
Floor10 huzixuan Posted 2007-02-17 23:13
高级用户 Posts 219 Credits 537 From 芜湖
Thanks to the brother's encouragement, especially to brother redtek. Although not appearing, I know that the brother has always been helping us.
Floor11 juventusryp Posted 2007-02-19 09:25
初级用户 Posts 40 Credits 88
set j!a!=%%a
I don't quite understand this sentence. I wonder if the LZ can explain it.
Floor12 xycoordinate Posted 2007-02-20 00:01
中级用户 Posts 228 Credits 493 From 安徽
Originally posted by juventusryp at 2007-2-18 08:25 PM:
I don't quite understand this line "set j!a!=%%a". I wonder if the LZ can explain it.

With everyone's help, I finally understand!!!

setlocal enabledelayedexpansion

set /?

......
When considering the current expansion limitations encountered when reading a line of text, delayed environment variable expansion is useful, not at execution time. The following example illustrates the problem with direct variable expansion:

set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "%VAR%" == "after" @echo If you see this, it worked
)

No message will be displayed because when the first IF statement is read, %VAR% in BOTH IF statements will be substituted; the reason is: it contains the style of IF, and IF is a compound statement. So the IF in the compound statement is actually comparing "before" and "after", which will never be equal. Similarly, the following example will not achieve the expected effect:

set LIST=
for %i in (*.txt) do set LIST=%LIST% %i
echo %LIST%

The reason is that it will not create a file list in the current directory, but just set the LIST variable to the last file found. This is also because %LIST% is only expanded once when the FOR statement is read; and at that time, the LIST variable is empty. Therefore, the FOR loop we are really executing is:

for %i in (*) do set LIST= %i

This loop continues to set LIST to the last file found.

Delayed environment variable expansion allows you to use a different character (!) to expand environment variables at execution time. If delayed variable expansion is enabled, the above example can be written as follows to achieve the expected effect:

set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo If you see this, it worked
)

set LIST=
for %i in (*.txt) do set LIST=!LIST! %i
echo %LIST%
......
Floor13 pxcok Posted 2007-02-20 05:00
新手上路 Posts 6 Credits 12
Floor14 huzixuan Posted 2007-02-20 05:13
高级用户 Posts 219 Credits 537 From 芜湖
Brother on the 13th floor explained it very clearly. I've always used it this way, but I can't clearly explain what this means!
Floor15 huzixuan Posted 2007-02-21 07:45
高级用户 Posts 219 Credits 537 From 芜湖
It's really an exciting thing to get the encouragement from the moderator!
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023