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 21:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Inquiry] How to judge the date in batch processing? View 6,723 Replies 17
Original Poster Posted 2006-09-28 06:55 ·  中国 湖南 长沙 电信
新手上路
Credits 9
Posts 3
Joined 2006-09-28 05:43
19-year member
UID 63891
Gender Male
Status Offline
Determine if today is the 20th. If yes, execute the copy command. How to write the batch? Please teach. (It's better not to display the DOS running window) Thanks!


————————————I am the divider——————————————


*********************************
Board affairs record
*********************************
Operation: Change the title
Reason: The original format does not conform to the board regulations
Original title: Novice asks for advice
Execution: 3742668
Punishment: First offense, forgiven.
Remarks: 1. It is recommended to read the stickied board regulations before posting
2. How to change the title?
Click the edit button at the lower right corner of the posted post, and then edit it.
**********************************


[ Last edited by 3742668 on 2006-9-29 at 09:07 ]
Floor 2 Posted 2006-09-28 07:05 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
In XP, you can use the format `if %date:~-2% equ 20` to judge whether the current day is the 20th in the system settings.

Not displaying the DOS running window is an old - fashioned topic. It can't be achieved only by batch processing commands. The landlord should give up this idea - unless relying on third - party software or other languages.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-09-28 21:14 ·  中国 湖南 长沙 电信
新手上路
Credits 9
Posts 3
Joined 2006-09-28 05:43
19-year member
UID 63891
Gender Male
Status Offline
Friend on the second floor,
I tried, but it seems it doesn't work.
Floor 4 Posted 2006-09-28 21:26 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
I remember that namem seemed to say that there is no day of the week after his time. Try changing this to %date:~8,2%
Floor 5 Posted 2006-09-28 21:33 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by NaturalJ0 at 2006-9-28 21:26:
I remember that namem seemed to say that there was no day of the week after his time
Try this for you %date:~8,2%


  Yes, sometimes there is a day of the week after my time, but most of the time there isn't. I don't know which setting is wrong. Still, your method is more universal. Also, the following method of intercepting characters can also be used, but it is a little more troublesome:

@echo off
for /f "tokens=3 delims=-" %%i in ("%date%") do echo The current system date is %%i day
pause
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-09-28 21:47 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
```
@echo off
if "%date:~8,-4%" equ "20" (
echo Here you just execute the copy command
) ELSE (
echo Today is not the 20th
)
PAUSE
```

[ Last edited by fastslz on 2006-9-28 at 21:51 ]
第一高手 第二高手

Floor 7 Posted 2006-10-01 03:29 ·  中国 江苏 镇江 电信
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
The result of %date% under XP and 2000 is opposite, one has the week in front and the other has it at the back.
www.jastyg.com
www.efengchi.com
Floor 8 Posted 2006-10-01 03:34 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
Yes, the date display in 2000 and XP is like this, but the original poster has already said it. It's the XP system. Actually, it's easy to handle for 2000 too. Just judge the system type by the output of the VER command, and then perform corresponding processing.
我今后在论坛的目标就是做个超级坏人!!!
Floor 9 Posted 2006-10-01 04:03 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by fastslz at 2006-9-28 21:47:

@echo off
if "%date:~8,-4%" equ "20" (
echo Here you execute the copy command
) ELSE (
echo Today is not the 20th
)
PAUSE


[ Last edited by fastslz on 2006 ...


Why does executing this become this?
C:\>兀
'"兀"' is not an internal or external command, nor is it a runnable program
or batch file.

????????
Floor 10 Posted 2006-10-01 06:00 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Don't save as a Unicode txt

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 11 Posted 2006-10-01 09:42 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Then what to save as?
Floor 12 Posted 2006-10-01 10:17 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Paste into Notepad》Save as type》All files》?.cmd》Encoding is still the default ANSI
第一高手 第二高手

Floor 13 Posted 2006-10-01 11:44 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Thanks!
By the way, what's the difference between Unicode and ANSI?
Floor 14 Posted 2006-10-01 12:05 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
This question is to be searched by yourself

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 15 Posted 2006-10-01 12:15 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
This is not easy to explain in a moment. Let's quote the post about encoding by moderator willsort.

willsort at 2006-7-23 12:15:
When the Notepad program saves a newly created document, if the encoding type is not specified, it will use the default ANSI type (for the Chinese version, it corresponds to GB code).

And when opening an already created document, it will analyze the encoding type of the document. It first judges whether there is a BOM (Byte Order Mark, with a length of 2-3 bytes) at the beginning of the document. If there is, it judges the encoding type according to its content: FF, FE (Unicode), FE, FF (Unicode big endian), EF, BB, BF (UTF-8) .

Because in fact, there are many non-ANSI encoded documents that are "plain text" without any BOM, so these documents cannot be simply judged as ANSI encoding. Instead, a series of statistical algorithms are needed to guess the document encoding according to the content of the document. Notepad uses the IsTextUnicode function to judge whether it is Unicode/Unicode big endian encoding, and uses IsTextUTF8 to judge whether it is UTF8 encoding.

But since it is a statistical algorithm, there are inevitably misjudgments, especially when the document content is too short. Because the sample capacity is too small, the probability of such misjudgment will increase significantly. For example, the famous joke that Microsoft has a grudge against China Unicom is that when Notepad opens an ANSI encoded document with only "China Unicom" two characters, the IsTextUTF8 function misjudges it as UTF8 encoding ; the same misjudgment also occurs in the IsTextUnicode function. For example, a document with "this app can break" which has a 4335 structure will be misjudged as Unicode encoding .

It should be noted that the possibility of such misjudgment is based on the premise that the text is short and its byte bit characteristics are not interfered. If the above text is slightly modified (even just adding a carriage return), then misjudgment is difficult to occur again.

The particularity of brother yuanyong630's plan is that its byte string not only has Unicode characteristics, but also is as long as 1288 bytes, that is to say, its Unicode characteristics are very strong, so it can resist the interference of some short strings that do not have Unicode characteristics, which is determined by the law of statistics. However, when the interference string is a little longer, the Unicode characteristics will be significantly interfered, until the IsTextUnicode function determines that it is not Unicode. So, some friends always can't test successfully, which should be related to the length and content of the attached batch processing code. You can test the code in .

Because other editors (such as Word / Wordpad / EditPlus / UltraEdit) use updated encoding type judgment algorithms, so the improvement in Unicode judgment is quite a lot, but the judgment of UTF8 is still not satisfactory. But because theoretically a completely accurate algorithm does not exist, so we can only rely on avoiding using non-ANSI documents without BOM, or manually specifying the encoding type when opening the document.

In addition, if these files with misjudged encoding types are saved with Notepad, it will be difficult to restore. If saved with misjudged encoding, a BOM mark will be added to the original document, and other editors will no longer be able to observe the original document. If saved with ANSI encoding, the original document will be converted as a Unicode document, and the possibility of restoration is close to zero.

Introduction to Unicode
http://my.opera.com/neutronstar/blog/index.dml/tag/encoding

Why does Microsoft have a grudge against China Unicom
http://blog.vckbase.com/localvar/archive/2005/07/12/9510.aspx

Notepad bug? Encoding issue?
http://weblogs.asp.net/cumpsd/archive/2004/02/27/81098.aspx

Bush Hid The Facts
http://www.shoutwire.com/comments/16341/Bush_Hid_The_Facts


[ Last edited by fastslz on 2006-10-1 at 12:16 ]
第一高手 第二高手

Forum Jump: