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-08-01 13:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Closed)ren a %date%.txt View 1,761 Replies 8
Original Poster Posted 2005-10-12 13:49 ·  中国 上海 电信
新手上路
Credits 4
Posts 2
Joined 2005-10-12 13:46
20-year member
UID 43392
Gender Male
Status Offline
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 ]
Floor 2 Posted 2005-10-12 15:14 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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"
Floor 3 Posted 2005-10-12 15:54 ·  中国 上海 电信
新手上路
Credits 4
Posts 2
Joined 2005-10-12 13:46
20-year member
UID 43392
Gender Male
Status Offline
Floor 4 Posted 2005-10-12 16:27 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 5 Posted 2005-10-12 16:41 ·  中国 广东 广州 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
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.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 6 Posted 2005-10-12 23:04 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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!
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 7 Posted 2005-10-13 00:23 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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.
Floor 8 Posted 2005-10-13 00:51 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2005-10-13 11:27 ·  中国 重庆 巴南区 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
In XP, use
for /f "tokens=1,2,3 delims=- " %a in ('date /t') do ren a %a%b.txt
http://www.msfans.net/bbs/
Forum Jump: