中国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-09-23 15:18
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » (Closed)ren a %date%.txt
Printable Version  1,853 / 8
Floor1 zxllxz Posted 2005-10-12 13:49
新手上路 Posts 2 Credits 4
Need to rename the generated file a, using ren a %date%.txt doesn't work. What is the syntax error? The purpose is to rename a generated every day to a text file named with the current day's time.

---------- Edited by willsort ----------
The solution is as follows:

ren a "%date%.txt" ——Floor 2

The file name generated by this method will contain the week count. To remove it depends on the date format of %date% in your system. If it is like "2005-10-15 Saturday", you can use

ren a "%date:~0,10%.txt" ——Floor 2

If it is like "Sat 2005-10-15", then you need to use

ren a "%date:~-10%.txt"

If it is other date formats, additional processing may be needed.

This is only a method that can be used in the NTVDM environment (DOS window) of the NT series platform. Under MSDOS6.22/7.10/Win9x, another solution is needed. Please search this forum.
---------- Edited by willsort ----------


[ Last edited by willsort on 2005-10-15 at 18:27 ]
Floor2 无奈何 Posted 2005-10-12 15:14
荣誉版主 Posts 356 Credits 1,338
Try this: ren a "%date%.txt"

In fact, like this, it may not necessarily get a format like "2005-10-12", which is related to the date format and regional settings. If you want to get the format shown above, please use the following method:

ren a "%date:~0,10%.txt"
Floor3 zxllxz Posted 2005-10-12 15:54
新手上路 Posts 2 Credits 4
Floor4 不得不爱 Posted 2005-10-12 16:27
超级版主 Posts 2,044 Credits 5,310 From 四川南充
I don't know why the "%date%.txt" needs to be enclosed in quotes to work correctly?
Floor5 JonePeng Posted 2005-10-12 16:41
金牌会员 Posts 1,883 Credits 4,562 From 广东广州
Originally posted by qwe1234567 at 2005-10-12 16:27:
I don't know why I need to enclose %date%.txt with "" to make it work correctly?


In CMD, try running echo %date% and see what the result is? As a moderator, you should be able to see why, heh heh.
Floor6 willsort Posted 2005-10-12 23:04
元老会员 Posts 1,512 Credits 4,432
Re 无奈何:

The %date:~0,10%v still cannot avoid incompatibility situations caused by different date formats or code pages. Moreover, in the XP environment, some changes in date variable formats are unexpected. For example, the following command line interception. The "Wednesday" will be displayed as "???" when the window font is "raster font", and normally displayed when it is "Lucida Console".


C:\Documents and Settings\wil>chcp 437
Active code page: 437

C:\Documents and Settings\wil>echo %date%
星期三 2005-10-12


Re qwe1234567 :

As a forum moderator, enthusiasm is the first element, management experience is the second element, and technical level can only be the third element. Brother qwe1234567's posting rate in the past few days has fully confirmed the possession of the first element, we will wait and see for the second element, and the third element may need a period of cultivation and accumulation.

Here, I hope that Brother qwe1234567 can continue to maintain this enthusiasm for DOS and the China DOS Union, and make contributions to the sustainable development of our forum!
Floor7 无奈何 Posted 2005-10-13 00:23
荣誉版主 Posts 356 Credits 1,338
to willsort

I tried when the code page is set to 437, it can't display Chinese. When the font is set to "Lucida Console", long Chinese characters can't be fully displayed, and when selecting Chinese characters, there will be a situation where half a Chinese character is selected. There are indeed problems after changing the code page. But I can't figure out the necessity of changing other code pages when using Chinese XP to handle Chinese documents.
Floor8 willsort Posted 2005-10-13 00:51
元老会员 Posts 1,512 Credits 4,432
Re 无奈何:

In the Chinese XP command line environment, there are still many possibilities of using the 437 code page, such as running 16-bit DOS programs, automatic switching of code pages; for example, in my current Chinese XP environment, entering the command line by running CMD, it defaults to the 437 code page, although this is a bit strange.
Floor9 chenhui530 Posted 2005-10-13 11:27
高级用户 Posts 273 Credits 772
In XP, use
for /f "tokens=1,2,3 delims=- " %a in ('date /t') do ren a %a%b.txt
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023