中国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-13 16:02
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS学习入门 & 精彩文章 (教学室) » A batch file of mine. Why doesn't it work? Please advise.
Printable Version  1,212 / 8
Floor1 骨灰龙 Posted 2004-02-11 00:00
中级用户 Posts 22 Credits 206
@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?
Floor2 xiaojun Posted 2004-02-12 00:00
银牌会员 Posts 499 Credits 2,202
Floor3 allul* Posted 2004-02-12 00:00
高级用户 Posts 167 Credits 612
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?
Floor4 Kinglion Posted 2004-02-12 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
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.
Floor5 骨灰龙 Posted 2004-02-12 00:00
中级用户 Posts 22 Credits 206
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?
Floor6 xiaojun Posted 2004-02-14 00:00
银牌会员 Posts 499 Credits 2,202
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...
Floor7 willsort Posted 2004-02-16 00:00
元老会员 Posts 1,512 Credits 4,432
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
Floor8 骨灰龙 Posted 2004-02-16 00:00
中级用户 Posts 22 Credits 206
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”
Floor9 willsort Posted 2004-04-14 00:00
元老会员 Posts 1,512 Credits 4,432
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
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023