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-24 05:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] How to remove the "/" in the date? View 4,026 Replies 27
Original Poster Posted 2006-10-11 04:07 ·  中国 辽宁 大连 联通
初级用户
Credits 30
Posts 11
Joined 2006-10-11 02:52
19-year member
UID 65248
Gender Male
From tre
Status Offline
In Windows batch files, I want to create a file named with the current date, but there can't be "/" in the file name, so I need to remove the "/" in the current date; that is, I want to convert "2006/10/10" into "20061010" to generate a "20061010.txt" file. I only know that set d=%date% can get the current date, but how to remove the "/"? Which expert knows?

[ Last edited by stableboy on 2006-10-11 at 06:08 ]
Floor 2 Posted 2006-10-11 04:17 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Floor 3 Posted 2006-10-11 04:32 ·  中国 辽宁 大连 联通
初级用户
Credits 30
Posts 11
Joined 2006-10-11 02:52
19-year member
UID 65248
Gender Male
From tre
Status Offline
Still not right,
%date:/=%
The output is %date:%=% Ah~!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
linjianhzcy +1 2008-09-14 16:22
Floor 4 Posted 2006-10-11 04:41 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
%date:~0,4%%date:~5,2%%date:~8,2%
Floor 5 Posted 2006-10-11 04:50 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\J>set a=2006/10/15

C:\Documents and Settings\J>echo %a:/=%
20061015

C:\Documents and Settings\J>_

==================================================

This is my operation situation
Floor 6 Posted 2006-10-11 05:48 ·  中国 辽宁 大连 联通
初级用户
Credits 30
Posts 11
Joined 2006-10-11 02:52
19-year member
UID 65248
Gender Male
From tre
Status Offline
Thanks to both of you, your methods both work...

The technology here is so difficult, I read a few posts and don't understand...
I need to work hard and study DOS batch processing hard. ~! .~!

Today I discovered this new forum, it's a great forum, I will study here from now on,


to NaturalJ0:
I'm sorry, after adding points to the above, when I tried to add points to you, I found that I can only add 2 points every 24 hours, so I can only add points to you tomorrow~! :P

[ Last edited by stableboy on 2006-10-11 at 05:54 ]
发现这个论坛,我以后就在这里学习了~!
Floor 7 Posted 2006-10-11 05:52 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 8 Posted 2006-10-11 06:07 ·  中国 云南 昆明 电信
初级用户
Credits 32
Posts 14
Joined 2006-10-09 07:50
19-year member
UID 65045
Status Offline
Experts, can you explain why?
:/ What is the function of this?
:~4,4 What is the function of this?
Floor 9 Posted 2006-10-11 06:46 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by ARCF at 2006-10-11 06:07:
Dears, can you explain why?
What is the function of ":/"?
What is the function of ":~4,4"?

Here, ":/" should be understood in combination with "%date:/=%", and its function is to replace all the "/" characters in the "%date%" variable with the symbol after "=", and here there is nothing after "=", that is, replace it with an empty one, actually removing all "/" symbols in the value of the "%date%" variable.

And here ":~4,4" should also be understood in combination with the above "%date:~4,4%", that is, intercept the fourth character to the eighth character in the "%date%" variable, that is, start from the fourth position and count four characters backward.

It is recommended to read the "set /?" help command carefully....
Floor 10 Posted 2006-10-11 09:15 ·  中国 浙江 衢州 电信
银牌会员
★★★
Credits 1,270
Posts 548
Joined 2004-05-31 00:00
22-year member
UID 25754
Gender Male
Status Offline
Still, the code like %date:/=% is concise and practical.
Floor 11 Posted 2006-10-12 05:14 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
```
For /F "tokens=1" %%a in ('date/t') do md %%a


The machine's time settings may vary.

Using for to analyze the output of date/t and then pass the date to md is better. I have been using it for 7 months.
I comprehensively utilized some system characteristics
Wrote a dynamic directory

[ Last edited by kcdsw on 2006-10-12 at 05:16 ]
```
Floor 12 Posted 2006-10-12 05:47 ·  中国 浙江 衢州 电信
银牌会员
★★★
Credits 1,270
Posts 548
Joined 2004-05-31 00:00
22-year member
UID 25754
Gender Male
Status Offline
The code of kcdsw, I tried it. In xpsp2, it can correctly create a directory with the current time.
Floor 13 Posted 2006-10-12 06:36 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Originally posted by kcdsw at 2006-10-12 05:14:

For /F "tokens=1" %%a in ('date/t') do md %%a


Machine time settings may vary

Use for to analyze the output of date/t and then pass the date to md, which is better...

Take advantage of system characteristics:
md %date%*

Adding * in front creates a directory for the current week.

The discussion is a bit off-topic.
Floor 14 Posted 2006-10-12 07:18 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by 3742668 at 2006-10-12 06:36:

Using system characteristics:
md %date%*

Adding * in front means creating a directory for the current week.

The discussion is a bit off-topic.


Tried it according to the moderator's method, but it doesn't seem to work.


C:\>md %date%*
The syntax of the file name, directory name, or volume label is incorrect.
Error occurred while processing: Wednesday*.

Floor 15 Posted 2006-10-12 07:27 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Re lxmxn:
Well, you can add 2>nul at the end.
Don't be deceived by error messages. The key is whether there is a newly created directory in the current directory.
Forum Jump: