中国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-02 15:29
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » 请问如何在批处理文件中引入系统日期作为生成的文件名? Translation: How to introduce the system date as the generated file name in a batch file?
Printable Version  2,779 / 15
Floor1 rocketer Posted 2006-12-01 00:48
新手上路 Posts 8 Credits 18
How to introduce the system date as the generated file name in a batch file?

I back up the MySQL database every day, typing the DOS command:
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql.sql
Then manually change the file name to a file name with the current date, such as: qyzx_mysql_20061128.sql

How to get the current system date in the batch file name and automatically add it to the command?
Further, is there a way to perform relative date calculations like getting yesterday, the day before yesterday, tomorrow, the day after tomorrow, etc.?
In addition, what syntax does the batch processing command belong to? What type of book should I read? I want to learn.
I am a beginner, I can hardly write batch processing, I can only simply fill the Dos command into the bat file.
Please give instructions from the experts, thank you! ~~~~~~~~~~
Floor2 youxi01 Posted 2006-12-01 02:30
高级用户 Posts 247 Credits 846 From 湖南==》广东
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%date::=-%.sql
Floor3 rocketer Posted 2006-12-01 04:03
新手上路 Posts 8 Credits 18
Thanks, but it didn't succeed. It seems there's something wrong somewhere........

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

D:\>mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%date::=-%.sql
mysqldump: Got error: 1102: Incorrect database name '2006-11-30.sql' when select
ing the database

D:\>myrun1

D:\>mysqldump -uroot -proot -B qyzx 2006-11-30.sql 1>c:\qyzx_mysql_星期四
mysqldump: Got error: 1102: Incorrect database name '2006-11-30.sql' when select
ing the database

D:\>
Floor4 rocketer Posted 2006-12-01 04:05
新手上路 Posts 8 Credits 18
The generated file is qyzx_mysql_Thursday with no extension.
Floor5 rocketer Posted 2006-12-01 04:10
新手上路 Posts 8 Credits 18
I added a pair of double quotes and changed it to
mysqldump -uroot -proot -B qyzx > "c:\qyzx_mysql_%date::=-%.sql"
The obtained backup file name is:
qyzx_mysql_Thursday 2006-11-30.sql
It's basically okay, thank you!!! But is there a better way,
Remove the Chinese character "Thursday" and the subsequent spaces and even the horizontal lines between the dates?
That is, according to the date format of 20061130? Thank you

Because I want the generated file name to be more standard, which can be directly typed on the command line,
File names with Chinese characters and spaces are not very good, thank you

[ Last edited by rocketer on 2006-11-30 at 04:34 PM ]
Floor6 ccwan Posted 2006-12-01 04:29
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
```
for /f "tokens=1-4 delims=:-" %%i in ("%date:~0,10%") do set DT=%%i%%j%%k
set DT=%DT: =0%
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%DT%.sql
```
Floor7 rocketer Posted 2006-12-01 05:20
新手上路 Posts 8 Credits 18
But I tried it, and the result is
qyzx_mysql_星期四020061.sql
It seems to be a small place that's different? ? ?
Please let the expert continue to take a look? ? ?
You can replace mysqldump -uroot -proot -B qyzx
with a dir
to see if the generated file name is what is expected, thank you,
I really don't understand, learning slowly
Floor8 ccwan Posted 2006-12-01 06:01
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
I'm sorry, our time formats are different. Change ("%date:~0,10%") to ("%date:~0,13%") and try again
Floor9 rocketer Posted 2006-12-01 06:55
新手上路 Posts 8 Credits 18
This time it's
qyzx_mysql_Thursday02006113.sql
If the zero after Thursday runs to the end, it will be correct.
Oh? So there are problems with different time formats? How do I know the time format?
Is there still a possibility of chaos when running on another machine after finally getting it right?
Also, the Chinese characters can't be eliminated??????
Thanks
Floor10 ccwan Posted 2006-12-01 07:07
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Win2000 test passed:
Floor11 rocketer Posted 2006-12-01 08:10
新手上路 Posts 8 Credits 18
It worked.
qyzx_mysql_Thursday20061130.sql
Thank you!!!
That week seems relatively difficult to eliminate, but it's already very good now. Thanks again!!!
I don't understand it now, I'll learn it slowly.
Floor12 ccwan Posted 2006-12-01 20:49
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
To remove the day of the week, change the code to:


You can analyze how to achieve it according to the differences between the two codes, and then you will understand.
Floor13 rocketer Posted 2006-12-02 09:55
新手上路 Posts 8 Credits 18
Thank you so much!!! I have bookmarked this post and thank you again!!!
Floor14 tao0610 Posted 2006-12-03 03:54
高级用户 Posts 218 Credits 579
xp sp2
Floor15 aheng Posted 2006-12-06 06:32
新手上路 Posts 2 Credits 4
Can be implemented with a software. I have it here. If you need it, add my QQ 403188070 and I'll send it to you
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023