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-06-28 19:25
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Urgent Help] Can't get it to work in the Win2000 Server edition View 633 Replies 8
Original Poster Posted 2005-03-04 00:00 ·  中国 广东 广州 移动
初级用户
Credits 138
Posts 13
Joined 2005-03-03 00:00
21-year member
UID 36693
Gender Male
Status Offline
A question about automatic renaming in a batch file?
Under the DOS mode of win2000svser, executing the a.bat batch command file should automatically rename the original file "temp.txt" to current date + temp.txt (that is, a file named: "2005-03-04temp.txt". Note that the current date should be the system's automatic date for that day. I'm asking how to write the batch commands in a.bat. Thanks in advance to all the experts for your guidance!
The statement below works in win2000, but unfortunately it doesn't work under server, because %date% returns "Friday 2005-03-04", and because of the space it says it's invalid, boo.... how can I extract it and solve this, urgent urgent urgent.....
echo ren test.txt %date%test.txt >temp.bat
Floor 2 Posted 2005-03-04 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
http://www.msfans.net/bbs/
Floor 3 Posted 2005-03-04 00:00 ·  中国 广东 广州 移动
初级用户
Credits 138
Posts 13
Joined 2005-03-03 00:00
21-year member
UID 36693
Gender Male
Status Offline
Many, many thanks to comrade chenhui530, thanks
Floor 4 Posted 2005-03-04 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
It's nothing, actually the for command in systems above 2k is already very powerful
http://www.msfans.net/bbs/
Floor 5 Posted 2005-03-07 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
ren temp.txt %date%temp.txt seems to work already, is it necessary to use for?
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 6 Posted 2005-03-07 00:00 ·  中国 广东 广州 移动
初级用户
Credits 138
Posts 13
Joined 2005-03-03 00:00
21-year member
UID 36693
Gender Male
Status Offline
The following is quoted from Climbing's post at 2005-3-7 2:56:54:
ren temp.txt %date%temp.txt
This command seems to work already, is it necessary to use for?

Because it is invalid in WIN2000SERVER, FOR is needed
Floor 7 Posted 2005-03-07 00:00 ·  中国 广东 广州 荔湾区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Brother Climbing: ren temp.txt %date%temp.txt looks like it has no syntax errors, but under Win2000 the value of %date% includes both the date and the weekday, and there is a space between the date and the weekday, so the command becomes ren temp.txt 2005-03-07 星期一temp.txt. Because of that extra space, it reports incorrect syntax. The correct way is to put ren's second parameter in double quotes, that is, ren temp.txt "%date%temp.txt". Unfortunately, the result of this command includes the “weekday”, which does not match the OP's requirement. I originally thought of using Strings to solve it. But in Win2000, the Strings command cannot store the output string into a variable. chenhui uses the for command so brilliantly! Awesome!!
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 8 Posted 2005-03-09 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
I tested the %date% variable using Windows 2003. I thought there should be no difference between 2003 and 2000, but I didn't expect there really is a difference (Microsoft systems are always this incompatible). The contents of my %date% variable under 2000 are:
C:\>echo %date%
Wednesday 2005-03-09 For this situation, you can write it like this: ren temp.txt %date:~-10%temp.txt If the weekday is at the end, you can write it as: ren temp.txt %date:~0,10%temp.txt Of course, chenhui's for command really is used very well and is also worth recommending. Strings really can't directly set variables under the NT environment, but it can be done with lmod.
strings right %date%, 10 | lmod /L1 set thedate= > temp.bat
call temp.bat
del temp.batOr without strings, use lmod directly:
date /t | lmod /L1 set thedate= > temp.bat
chcp 936
call temp.bat
del temp.bat
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 9 Posted 2005-03-09 00:00 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
So "%date:~0,10%" can be used like that! That even saves Strings and Lmod. Haha, I learned another trick.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Forum Jump: