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-08-13 20:15
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » A batch file of mine. Why doesn't it work? Please advise. View 1,214 Replies 8
Original Poster Posted 2004-02-11 00:00 ·  中国 山西 太原 联通
中级用户
Credits 206
Posts 22
Joined 2004-02-05 00:00
22-year member
UID 16772
Gender Male
Status Offline
@echo off
if %date% == "2002.1.1" goto del

:del
deltree %temp%\*.*

:end
exit

I want to check the current date; if it matches, then delete the temporary files. If not, then exit. But why does it go straight to the delete command?
Floor 2 Posted 2004-02-12 00:00 ·  中国 重庆 电信
银牌会员
★★★
Credits 2,202
Posts 499
Joined 2003-06-12 00:00
23-year member
UID 4876
Gender Male
Status Offline
一年四季,枫叶红了又红;人生四季,失去的,还能再来吗?—— !
Floor 3 Posted 2004-02-12 00:00 ·  中国 辽宁 沈阳 中移铁通
高级用户
★★
Credits 612
Posts 167
Joined 2003-12-01 00:00
22-year member
UID 13615
Gender Female
Status Offline
Question for the poster above: should this line be added under
if %date% == "2002.1.1" goto del or should I change it to exactly what you wrote?
别问我是谁.
Floor 4 Posted 2004-02-12 00:00 ·  中国 辽宁 沈阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
Your date format is wrong. It should be in the format “XXXX-XX-XX Weekday X” (in the XP system). Also, the %DATE% variable is invalid in DRDOS.
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 5 Posted 2004-02-12 00:00 ·  中国 山西 太原 联通
中级用户
Credits 206
Posts 22
Joined 2004-02-05 00:00
22-year member
UID 16772
Gender Male
Status Offline
To the poster above.
I did what you said, but it doesn't work. It says, “Weekday X is not expected at this time”
Why?
Floor 6 Posted 2004-02-14 00:00 ·  中国 重庆 电信
银牌会员
★★★
Credits 2,202
Posts 499
Joined 2003-06-12 00:00
23-year member
UID 4876
Gender Male
Status Offline
The following is quoted from a post by allul* at 2004-2-12 10:30:34:
Question for the poster above: should this line be added under
if %date% == "2002.1.1" goto del  or should I change it to exactly what you wrote?


As long as it meets the condition you gave, then Goto...
You can try IF NOT %DATE%=="2002.1.1" EXIT and see what result you get...
一年四季,枫叶红了又红;人生四季,失去的,还能再来吗?—— !
Floor 7 Posted 2004-02-16 00:00 ·  中国 河北 石家庄 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re Bone Ash Dragon:

You didn't say what system and environment you're using, and I'm also very unfamiliar with the NT-series environment, so I can't judge whether your date format is right or wrong. I can only reply regarding the following issue:

@echo off
if %date% == "2002.1.1" goto del
rem As xiaojun said, the use of the jump statement here is problematic.
rem Because according to your code, whether the condition is true or not, it will directly execute the del block below.
rem That's why it runs deltree regardless of the condition.
rem And your %date%=="2002.1.1" also seems to be problematic.
rem Unless the original value of the date variable contains quotation marks, this way of adding quotes only to the latter value is wrong.
rem It should instead be changed to "%date%"=="2002.1.1".
rem Also, the data variable is not directly provided by the system in all environments; for example, in 98 it needs to be obtained manually.

:del
deltree %temp%\*.*

:end
exit
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2004-02-16 00:00 ·  中国 山西 太原 联通
中级用户
Credits 206
Posts 22
Joined 2004-02-05 00:00
22-year member
UID 16772
Gender Male
Status Offline
Thanks, everyone.
RE:WILLSORT
I'm using WIN2003SERVER. It may be because of the system. I made changes according to everyone's suggestions, but it still didn't work. I keep getting error messages. It says, “Weekday X==2001.1.1 is not expected at this time”
Floor 9 Posted 2004-04-14 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re Bone Ash Dragon:

I found a win2000 machine and did a test. Its date format is “Wednesday 2004-04-14”. Based on that format, I came up with the following program, and it runs successfully. If it's another platform, please modify the contents accordingly based on the date format. The key correction is in the IF statement, with the following points:

1. The strings on both sides of the equals sign need to be protected with quotation marks, because the latter string contains spaces;
2. The date must strictly match the system's format, which means the weekday must be included, and its position must also be fixed;
3. Change GOTO DEL to GOTO END in the negated case;
4. Add the /Y no-confirmation switch to DELTREE


@echo off
if not "%date%" == "星期三 2004-04-14" goto end

:del
deltree /y %temp%\*.*

:end
exit
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: