![]() |
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-15 12:31 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved] How to remove the "/" in the date? |
| Printable Version 4,420 / 27 |
| Floor1 stableboy | Posted 2006-10-11 04:07 |
| 初级用户 Posts 11 Credits 30 From tre | |
|
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 ] |
|
| Floor2 NaturalJ0 | Posted 2006-10-11 04:17 |
| 银牌会员 Posts 533 Credits 1,181 | |
| Floor3 stableboy | Posted 2006-10-11 04:32 |
| 初级用户 Posts 11 Credits 30 From tre | |
|
Still not right,
%date:/=% The output is %date:%=% Ah~! |
|
| Floor4 vkill | Posted 2006-10-11 04:41 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
%date:~0,4%%date:~5,2%%date:~8,2%
|
|
| Floor5 NaturalJ0 | Posted 2006-10-11 04:50 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
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 |
|
| Floor6 stableboy | Posted 2006-10-11 05:48 |
| 初级用户 Posts 11 Credits 30 From tre | |
|
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 ] |
|
| Floor7 不得不爱 | Posted 2006-10-11 05:52 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
In the 2000 system, it is correct to use %date:~4,4%%date:~9,2%%date:~12,2%
|
|
| Floor8 ARCF | Posted 2006-10-11 06:07 |
| 初级用户 Posts 14 Credits 32 | |
|
Experts, can you explain why?
:/ What is the function of this? :~4,4 What is the function of this? |
|
| Floor9 lxmxn | Posted 2006-10-11 06:46 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by ARCF at 2006-10-11 06:07: 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.... |
|
| Floor10 weilong888 | Posted 2006-10-11 09:15 |
| 银牌会员 Posts 548 Credits 1,270 | |
|
Still, the code like %date:/=% is concise and practical.
|
|
| Floor11 kcdsw | Posted 2006-10-12 05:14 |
| 中级用户 Posts 179 Credits 404 | |
|
```
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 ] ``` |
|
| Floor12 weilong888 | Posted 2006-10-12 05:47 |
| 银牌会员 Posts 548 Credits 1,270 | |
|
The code of kcdsw, I tried it. In xpsp2, it can correctly create a directory with the current time.
|
|
| Floor13 3742668 | Posted 2006-10-12 06:36 |
| 荣誉版主 Posts 718 Credits 2,013 | |
Originally posted by kcdsw at 2006-10-12 05:14: Take advantage of system characteristics: Adding * in front creates a directory for the current week. The discussion is a bit off-topic. |
|
| Floor14 lxmxn | Posted 2006-10-12 07:18 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by 3742668 at 2006-10-12 06:36: Tried it according to the moderator's method, but it doesn't seem to work.
|
|
| Floor15 3742668 | Posted 2006-10-12 07:27 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
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. |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |