中国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-17 05:54
47,813 topics / 349,903 posts / today 0 new / 48,259 members
DOS疑难解答 & 问题讨论 (解答室) » [Urgent Help] Can't get it to work in the Win2000 Server edition
Printable Version  692 / 8
Floor1 影视狂奔 Posted 2005-03-04 00:00
初级用户 Posts 13 Credits 138
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
Floor2 chenhui530 Posted 2005-03-04 00:00
高级用户 Posts 273 Credits 772
Floor3 影视狂奔 Posted 2005-03-04 00:00
初级用户 Posts 13 Credits 138
Many, many thanks to comrade chenhui530, thanks
Floor4 chenhui530 Posted 2005-03-04 00:00
高级用户 Posts 273 Credits 772
It's nothing, actually the for command in systems above 2k is already very powerful
Floor5 Climbing Posted 2005-03-07 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
ren temp.txt %date%temp.txt seems to work already, is it necessary to use for?
Floor6 影视狂奔 Posted 2005-03-07 00:00
初级用户 Posts 13 Credits 138
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
Floor7 JonePeng Posted 2005-03-07 00:00
金牌会员 Posts 1,883 Credits 4,562 From 广东广州
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!!
Floor8 Climbing Posted 2005-03-09 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
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
Floor9 JonePeng Posted 2005-03-09 00:00
金牌会员 Posts 1,883 Credits 4,562 From 广东广州
So "%date:~0,10%" can be used like that! That even saves Strings and Lmod. Haha, I learned another trick.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023